aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2023-02-08 10:37:33 +0100
committert3sserakt <t3ss@posteo.de>2023-02-08 10:37:33 +0100
commit6b83e9a453ffc9ea0347a7e725c3a9b6d2a32517 (patch)
tree7bc7b5f2d65ebaf28713f8a69f11f619b2044f4b /src
parentbe0909d95bc5fa961b91223729b9858a864e3f61 (diff)
downloadgnunet-6b83e9a453ffc9ea0347a7e725c3a9b6d2a32517.tar.gz
gnunet-6b83e9a453ffc9ea0347a7e725c3a9b6d2a32517.zip
TNG: Added performance test case.
Diffstat (limited to 'src')
-rw-r--r--src/transport/Makefile.am23
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_performance.c508
-rwxr-xr-xsrc/transport/test_transport_simple_send_performance.sh11
-rw-r--r--src/transport/test_transport_simple_send_performance_topo.conf6
-rw-r--r--src/transport/transport-testing-cmds.h22
-rw-r--r--src/transport/transport-testing2.h23
-rw-r--r--src/transport/transport_api_cmd_send_simple_performance.c219
7 files changed, 811 insertions, 1 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 5acba3a4e..eeafab840 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -130,6 +130,7 @@ libgnunettransporttesting2_la_SOURCES = \
130 transport_api_cmd_start_peer.c \ 130 transport_api_cmd_start_peer.c \
131 transport_api_cmd_stop_peer.c \ 131 transport_api_cmd_stop_peer.c \
132 transport_api_cmd_send_simple.c \ 132 transport_api_cmd_send_simple.c \
133 transport_api_cmd_send_simple_performance.c \
133 transport-testing2.c transport-testing2.h \ 134 transport-testing2.c transport-testing2.h \
134 transport-testing-cmds.h \ 135 transport-testing-cmds.h \
135 transport-testing-filenames2.c \ 136 transport-testing-filenames2.c \
@@ -357,6 +358,7 @@ plugin_LTLIBRARIES = \
357 $(HTTPS_SERVER_PLUGIN_LA) \ 358 $(HTTPS_SERVER_PLUGIN_LA) \
358 $(WLAN_PLUGIN_LA) \ 359 $(WLAN_PLUGIN_LA) \
359 $(BT_PLUGIN_LA) \ 360 $(BT_PLUGIN_LA) \
361 libgnunet_test_transport_plugin_cmd_simple_send_performance.la \
360 libgnunet_test_transport_plugin_cmd_nat_upnp.la \ 362 libgnunet_test_transport_plugin_cmd_nat_upnp.la \
361 libgnunet_test_transport_plugin_cmd_simple_send.la \ 363 libgnunet_test_transport_plugin_cmd_simple_send.la \
362 libgnunet_test_transport_plugin_cmd_simple_send_broadcast.la \ 364 libgnunet_test_transport_plugin_cmd_simple_send_broadcast.la \
@@ -414,6 +416,23 @@ libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \
414libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \ 416libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
415 $(GN_PLUGIN_LDFLAGS) 417 $(GN_PLUGIN_LDFLAGS)
416 418
419libgnunet_test_transport_plugin_cmd_simple_send_performance_la_SOURCES = \
420 test_transport_plugin_cmd_simple_send_performance.c
421libgnunet_test_transport_plugin_cmd_simple_send_performance_la_LIBADD = \
422 libgnunettransporttesting2.la \
423 libgnunettransportapplication.la \
424 libgnunettransportcore.la \
425 $(top_builddir)/src/testing/libgnunettesting.la \
426 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
427 $(top_builddir)/src/statistics/libgnunetstatistics.la \
428 $(top_builddir)/src/hello/libgnunethello.la \
429 $(top_builddir)/src/ats/libgnunetats.la \
430 $(top_builddir)/src/arm/libgnunetarm.la \
431 $(top_builddir)/src/util/libgnunetutil.la \
432 $(LTLIBINTL)
433libgnunet_test_transport_plugin_cmd_simple_send_performance_la_LDFLAGS = \
434 $(GN_PLUGIN_LDFLAGS)
435
417libgnunet_test_transport_plugin_cmd_simple_send_broadcast_la_SOURCES = \ 436libgnunet_test_transport_plugin_cmd_simple_send_broadcast_la_SOURCES = \
418 test_transport_plugin_cmd_simple_send_broadcast.c 437 test_transport_plugin_cmd_simple_send_broadcast.c
419libgnunet_test_transport_plugin_cmd_simple_send_broadcast_la_LIBADD = \ 438libgnunet_test_transport_plugin_cmd_simple_send_broadcast_la_LIBADD = \
@@ -760,7 +779,8 @@ endif
760# Only test TNG if we run experimental 779# Only test TNG if we run experimental
761if HAVE_EXPERIMENTAL 780if HAVE_EXPERIMENTAL
762check_SCRIPTS= \ 781check_SCRIPTS= \
763test_transport_nat_icmp_tcp.sh \ 782 test_transport_simple_send_performance.sh \
783 test_transport_nat_icmp_tcp.sh \
764 test_transport_nat_upnp.sh \ 784 test_transport_nat_upnp.sh \
765 test_transport_simple_send_string.sh \ 785 test_transport_simple_send_string.sh \
766 test_transport_simple_send.sh \ 786 test_transport_simple_send.sh \
@@ -1510,6 +1530,7 @@ test_transport_api_slow_ats_LDADD = \
1510 1530
1511 1531
1512EXTRA_DIST = \ 1532EXTRA_DIST = \
1533test_transport_simple_send_performance.sh \
1513test_transport_nat_icmp_tcp.sh \ 1534test_transport_nat_icmp_tcp.sh \
1514test_transport_nat_upnp.sh \ 1535test_transport_nat_upnp.sh \
1515test_transport_simple_send_string.sh \ 1536test_transport_simple_send_string.sh \
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
50static struct GNUNET_TESTING_Command block_send;
51
52static struct GNUNET_TESTING_Command block_receive;
53
54static struct GNUNET_TESTING_Command connect_peers;
55
56static struct GNUNET_TESTING_Command local_prepared;
57
58static struct GNUNET_TESTING_Command start_peer;
59
60static struct GNUNET_TESTING_Interpreter *is;
61
62static struct GNUNET_CONTAINER_MultiPeerMap *senders;
63
64struct 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 */
87static int
88check_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 */
100static void
101handle_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
188struct GNUNET_TESTING_BarrierList*
189get_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 */
216static void
217all_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 */
237static void
238handle_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 */
259static void *
260notify_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 */
281static void
282all_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 */
314static struct GNUNET_TESTING_Interpreter *
315start_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 */
476void *
477libgnunet_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 */
498void *
499libgnunet_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 */
diff --git a/src/transport/test_transport_simple_send_performance.sh b/src/transport/test_transport_simple_send_performance.sh
new file mode 100755
index 000000000..12798c2f0
--- /dev/null
+++ b/src/transport/test_transport_simple_send_performance.sh
@@ -0,0 +1,11 @@
1#!/bin/bash
2if ! [ -d "/run/netns" ]; then
3 echo You have to create the directory /run/netns.
4fi
5if [ -f /proc/sys/kernel/unprivileged_userns_clone ]; then
6 if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" != 1 ]; then
7 echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
8 exit 78
9 fi
10fi
11exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_performance_topo.conf"
diff --git a/src/transport/test_transport_simple_send_performance_topo.conf b/src/transport/test_transport_simple_send_performance_topo.conf
new file mode 100644
index 000000000..1c73952d2
--- /dev/null
+++ b/src/transport/test_transport_simple_send_performance_topo.conf
@@ -0,0 +1,6 @@
1M:2
2N:1
3X:0
4T:libgnunet_test_transport_plugin_cmd_simple_send_performance
5P:1:1|{connect:{P:1:2:tcp}}
6P:1:2|{connect:{P:1:1:tcp}} \ No newline at end of file
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index 46f6045dc..6e3c761f2 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -304,6 +304,28 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
304 struct GNUNET_TESTING_NetjailTopology * 304 struct GNUNET_TESTING_NetjailTopology *
305 topology); 305 topology);
306 306
307/**
308 *
309 *
310 * @param label name for command.
311 * @param start_peer_label Label of the cmd to start a peer.
312 * @param create_label Label of the cmd which started the test system.
313 * @param num Number globally identifying the node.
314 * @param size The size of the test message to send.
315 * @param max_send The number of messages to send.
316 * @param topology The topology for the test setup.
317 * @return command.
318 */
319struct GNUNET_TESTING_Command
320GNUNET_TRANSPORT_cmd_send_simple_performance (const char *label,
321 const char *start_peer_label,
322 const char *create_label,
323 uint32_t num,
324 int size,
325 int max_send,
326 struct GNUNET_TESTING_NetjailTopology *
327 topology);
328
307 329
308/** 330/**
309 * Create command. 331 * Create command.
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
index b5db28500..b9e492219 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -435,6 +435,25 @@ struct GNUNET_TRANSPORT_TESTING_TestMessage
435 */ 435 */
436 uint32_t num GNUNET_PACKED; 436 uint32_t num GNUNET_PACKED;
437}; 437};
438
439struct GNUNET_TRANSPORT_TESTING_PerformanceTestMessage
440{
441 /**
442 * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE.
443 */
444 struct GNUNET_MessageHeader header;
445
446 /**
447 * Time this message was send via transport api.
448 */
449 struct GNUNET_TIME_AbsoluteNBO time_send;
450
451 /**
452 * Monotonically increasing counter throughout the test.
453 */
454 uint32_t num GNUNET_PACKED;
455};
456
438GNUNET_NETWORK_STRUCT_END 457GNUNET_NETWORK_STRUCT_END
439 458
440 459
@@ -774,6 +793,10 @@ GNUNET_TRANSPORT_TESTING_send (
774 */ 793 */
775#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346 794#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346
776 795
796/**
797 * Message type used by #().
798 */
799#define GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE 12347
777 800
778/** 801/**
779 * Type of the closure argument to pass to 802 * Type of the closure argument to pass to
diff --git a/src/transport/transport_api_cmd_send_simple_performance.c b/src/transport/transport_api_cmd_send_simple_performance.c
new file mode 100644
index 000000000..7e195d9ef
--- /dev/null
+++ b/src/transport/transport_api_cmd_send_simple_performance.c
@@ -0,0 +1,219 @@
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 testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.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/**
39 * Struct to hold information for callbacks.
40 *
41 */
42struct SendSimplePerfState
43{
44 /**
45 * Context for our asynchronous completion.
46 */
47 struct GNUNET_TESTING_AsyncContext ac;
48
49 /**
50 * Label of the cmd to start a peer.
51 *
52 */
53 const char *start_peer_label;
54
55 /**
56 * Label of the cmd which started the test system.
57 *
58 */
59 const char *create_label;
60
61 /**
62 * The topology we get the connected nodes from.
63 */
64 struct GNUNET_TESTING_NetjailTopology *topology;
65
66 /**
67 * Size of the message in bytes.
68 */
69 int size;
70
71 /**
72 * Maximum number of messages per peer.
73 */
74 int max_send;
75};
76
77struct MQWrapper
78{
79 /**
80 * State of the command.
81 */
82 struct SendSimplePerfState *sss;
83
84 /**
85 * Message queue for a peer.
86 */
87 struct GNUNET_MQ_Handle *mq;
88
89 /**
90 * Number of messages allready send.
91 */
92 uint32_t num_send;
93};
94
95/**
96 * The cleanup function of this cmd frees resources the cmd allocated.
97 *
98 */
99static void
100send_simple_cleanup (void *cls)
101{
102 struct SendSimpleState *sss = cls;
103
104 GNUNET_free (sss);
105}
106
107
108static void
109send_simple_single (void *cls)
110{
111 struct MQWrapper *mq_wrapper = cls;
112 struct GNUNET_MQ_Envelope *env;
113 struct GNUNET_TRANSPORT_TESTING_PerformanceTestMessage *test;
114 struct GNUNET_TIME_Absolute now;
115
116 now = GNUNET_TIME_absolute_get ();
117 mq_wrapper->num_send++;
118 LOG (GNUNET_ERROR_TYPE_DEBUG,
119 "Sending simple test message with size %llu number %u with mq %p max %llu\n",
120 mq_wrapper->sss->size,
121 mq_wrapper->num_send,
122 mq_wrapper->mq,
123 mq_wrapper->sss->max_send);
124
125 env = GNUNET_MQ_msg_extra (test,
126 mq_wrapper->sss->size - sizeof(*test),
127 GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE);
128 test->num = htonl (mq_wrapper->num_send);
129 test->time_send = GNUNET_TIME_absolute_hton (now);
130 memset (&test[1],
131 '1',
132 mq_wrapper->sss->size - sizeof(*test));
133 GNUNET_MQ_send (mq_wrapper->mq,
134 env);
135 if (mq_wrapper->sss->max_send > mq_wrapper->num_send)
136 GNUNET_SCHEDULER_add_now (&send_simple_single, mq_wrapper);
137 else
138 GNUNET_TESTING_async_finish (&mq_wrapper->sss->ac);
139}
140
141
142static int
143send_simple_cb (void *cls,
144 const struct GNUNET_ShortHashCode *key,
145 void *value)
146{
147 struct SendSimplePerfState *sss = cls;
148 struct GNUNET_MQ_Handle *mq = value;
149 struct MQWrapper *mq_wrapper = GNUNET_new (struct MQWrapper);
150
151 mq_wrapper->sss = sss;
152 mq_wrapper->mq = mq;
153 send_simple_single (mq_wrapper);
154
155 return GNUNET_OK;
156}
157
158
159/**
160 * The run method of this cmd will send a simple message to the connected peers.
161 *
162 */
163static void
164send_simple_run (void *cls,
165 struct GNUNET_TESTING_Interpreter *is)
166{
167 struct SendSimplePerfState *sss = cls;
168 const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
169 const struct GNUNET_TESTING_Command *peer1_cmd;
170 const struct GNUNET_TESTING_Command *system_cmd;
171 const struct GNUNET_TESTING_System *tl_system;
172
173
174 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
175 sss->start_peer_label);
176 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
177 &connected_peers_map);
178
179 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
180 sss->create_label);
181 GNUNET_TESTING_get_trait_test_system (system_cmd,
182 &tl_system);
183
184 GNUNET_CONTAINER_multishortmap_iterate (
185 (struct GNUNET_CONTAINER_MultiShortmap *)
186 connected_peers_map, send_simple_cb,
187 sss);
188}
189
190
191struct GNUNET_TESTING_Command
192GNUNET_TRANSPORT_cmd_send_simple_performance (const char *label,
193 const char *start_peer_label,
194 const char *create_label,
195 uint32_t num,
196 int size,
197 int max_send,
198 struct GNUNET_TESTING_NetjailTopology *
199 topology)
200{
201 struct SendSimplePerfState *sss;
202 struct GNUNET_TESTING_Command cmd;
203
204 sss = GNUNET_new (struct SendSimplePerfState);
205 sss->start_peer_label = start_peer_label;
206 sss->create_label = create_label;
207 sss->topology = topology;
208 sss->size = size;
209 sss->max_send = max_send;
210
211 cmd = GNUNET_TESTING_command_new (sss,
212 label,
213 &send_simple_run,
214 &send_simple_cleanup,
215 NULL,
216 &sss->ac);
217 cmd.asynchronous_finish = GNUNET_YES;
218 return cmd;
219}