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