diff options
Diffstat (limited to 'src/transport/transport_api_cmd_send_simple_performance.c')
-rw-r--r-- | src/transport/transport_api_cmd_send_simple_performance.c | 219 |
1 files changed, 219 insertions, 0 deletions
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 | */ | ||
42 | struct 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 | |||
77 | struct 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 | */ | ||
99 | static void | ||
100 | send_simple_cleanup (void *cls) | ||
101 | { | ||
102 | struct SendSimpleState *sss = cls; | ||
103 | |||
104 | GNUNET_free (sss); | ||
105 | } | ||
106 | |||
107 | |||
108 | static void | ||
109 | send_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 | |||
142 | static int | ||
143 | send_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 | */ | ||
163 | static void | ||
164 | send_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 | |||
191 | struct GNUNET_TESTING_Command | ||
192 | GNUNET_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 | } | ||