aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_plugin_cmd_simple_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send.c')
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c248
1 files changed, 248 insertions, 0 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
new file mode 100644
index 000000000..4b5018b60
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -0,0 +1,248 @@
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_ng_lib.h"
28#include "gnunet_util_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/**
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
45
46/**
47 * The name for the configuration file of the specific node.
48 *
49 */
50char *cfgname;
51
52/**
53 * Flag indicating if all peers have been started.
54 *
55 */
56unsigned int are_all_peers_started;
57
58
59/**
60 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
61 * received.
62 *
63 */
64static int
65check_test (void *cls,
66 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
67{
68 return GNUNET_OK;
69}
70
71
72/**
73 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
74 * being received.
75 *
76 */
77static void
78handle_test (void *cls,
79 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
80{
81 LOG (GNUNET_ERROR_TYPE_ERROR,
82 "message received\n");
83}
84
85
86/**
87 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
88 * being received.
89 *
90 */
91static int
92check_test2 (void *cls,
93 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
94{
95 return GNUNET_OK;
96}
97
98
99/**
100 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
101 * being received.
102 *
103 */
104static void
105handle_test2 (void *cls,
106 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
107{
108 LOG (GNUNET_ERROR_TYPE_ERROR,
109 "message received\n");
110}
111
112
113/**
114 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
115 *
116 */
117static void
118all_peers_started ()
119{
120 are_all_peers_started = GNUNET_YES;
121 LOG (GNUNET_ERROR_TYPE_ERROR,
122 "setting are_all_peers_started: %d\n",
123 are_all_peers_started);
124}
125
126
127/**
128 * Function to start a local test case.
129 *
130 * @param write_message Callback to send a message to the master loop.
131 * @param router_ip Global address of the network namespace.
132 * @param node_ip Local address of a node i a network namespace.
133 * @param m The number of the node in a network namespace.
134 * @param n The number of the network namespace.
135 * @param local_m The number of nodes in a network namespace.
136 */
137static void
138start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
139 char *node_ip,
140 char *m,
141 char *n,
142 char *local_m)
143{
144
145 GNUNET_asprintf (&cfgname,
146 "test_transport_api2_tcp_node%s.conf",
147 n);
148
149 LOG (GNUNET_ERROR_TYPE_ERROR,
150 "plugin cfgname: %s\n",
151 cfgname);
152
153 LOG (GNUNET_ERROR_TYPE_ERROR,
154 "node ip: %s\n",
155 node_ip);
156
157 GNUNET_asprintf (&testdir,
158 "%s%s%s",
159 BASE_DIR,
160 m,
161 n);
162
163 struct GNUNET_MQ_MessageHandler handlers[] = {
164 GNUNET_MQ_hd_var_size (test,
165 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
166 struct GNUNET_TRANSPORT_TESTING_TestMessage,
167 NULL),
168 GNUNET_MQ_hd_var_size (test2,
169 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
170 struct GNUNET_TRANSPORT_TESTING_TestMessage,
171 NULL),
172 GNUNET_MQ_handler_end ()
173 };
174
175 struct GNUNET_TESTING_Command commands[] = {
176 GNUNET_TESTING_cmd_system_create ("system-create",
177 testdir),
178 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
179 "system-create",
180 m,
181 n,
182 local_m,
183 handlers,
184 cfgname),
185 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
186 write_message),
187 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
188 &are_all_peers_started),
189 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
190 "start-peer"),
191 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
192 m,
193 n,
194 (atoi (n) - 1) * atoi (local_m) + atoi (
195 m),
196 "start-peer"),
197 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
198 "start-peer"),
199 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
200 "system-create"),
201 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
202 write_message)
203 };
204
205 GNUNET_TESTING_run (NULL,
206 commands,
207 GNUNET_TIME_UNIT_FOREVER_REL);
208
209}
210
211
212/**
213 * Entry point for the plugin.
214 *
215 * @param cls NULL
216 * @return the exported block API
217 */
218void *
219libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
220{
221 struct GNUNET_TESTING_PluginFunctions *api;
222
223 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
224 api->start_testcase = &start_testcase;
225 api->all_peers_started = &all_peers_started;
226 return api;
227}
228
229
230/**
231 * Exit point from the plugin.
232 *
233 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
234 * @return NULL
235 */
236void *
237libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
238{
239 struct GNUNET_TESTING_PluginFunctions *api = cls;
240
241 GNUNET_free (api);
242 GNUNET_free (testdir);
243 GNUNET_free (cfgname);
244 return NULL;
245}
246
247
248/* end of plugin_cmd_simple_send.c */