aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-09-20 14:19:31 +0200
committert3sserakt <t3ss@posteo.de>2021-09-20 14:19:31 +0200
commit200d95be000f9c0a9beca91370e754368d6bc59a (patch)
tree734cca2482474ce0de5de5a47815be50f5906ac4 /src
parent0e808e708cbdc498a0843d3432143a91f5195bbe (diff)
downloadgnunet-200d95be000f9c0a9beca91370e754368d6bc59a.tar.gz
gnunet-200d95be000f9c0a9beca91370e754368d6bc59a.zip
- added missing testcase plugin
Diffstat (limited to 'src')
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c242
1 files changed, 242 insertions, 0 deletions
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
new file mode 100644
index 000000000..90e474aea
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -0,0 +1,242 @@
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_udp_backchannel_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 message_received = GNUNET_YES;
89}
90
91
92/**
93 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
94 *
95 */
96static void
97all_peers_started ()
98{
99 are_all_peers_started = GNUNET_YES;
100 LOG (GNUNET_ERROR_TYPE_ERROR,
101 "setting are_all_peers_started: %d\n",
102 are_all_peers_started);
103}
104
105
106/**
107 * Function to start a local test case.
108 *
109 * @param write_message Callback to send a message to the master loop.
110 * @param router_ip Global address of the network namespace.
111 * @param node_ip Local address of a node i a network namespace.
112 * @param m The number of the node in a network namespace.
113 * @param n The number of the network namespace.
114 * @param local_m The number of nodes in a network namespace.
115 */
116static void
117start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
118 char *node_ip,
119 char *m,
120 char *n,
121 char *local_m)
122{
123
124 unsigned int n_int, m_int, local_m_int, num;
125
126 struct GNUNET_TESTING_NetjailTopology *topology =
127 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
128
129 sscanf (m, "%u", &m_int);
130 sscanf (n, "%u", &n_int);
131 sscanf (local_m, "%u", &local_m_int);
132
133
134 if (0 == n_int)
135 num = m_int;
136 else
137 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
138
139 GNUNET_asprintf (&cfgname,
140 "test_transport_api2_tcp_node1.conf");
141
142 LOG (GNUNET_ERROR_TYPE_ERROR,
143 "plugin cfgname: %s\n",
144 cfgname);
145
146 LOG (GNUNET_ERROR_TYPE_ERROR,
147 "node ip: %s\n",
148 node_ip);
149
150 GNUNET_asprintf (&testdir,
151 "%s%s%s",
152 BASE_DIR,
153 m,
154 n);
155
156 struct GNUNET_MQ_MessageHandler handlers[] = {
157 GNUNET_MQ_hd_var_size (test,
158 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
159 struct GNUNET_TRANSPORT_TESTING_TestMessage,
160 NULL),
161 GNUNET_MQ_handler_end ()
162 };
163
164 struct GNUNET_TESTING_Command commands[] = {
165 GNUNET_TESTING_cmd_system_create ("system-create",
166 testdir),
167 GNUNET_TRANSPORT_cmd_start_peer_v3 ("start-peer",
168 "system-create",
169 num,
170 node_ip,
171 handlers,
172 cfgname),
173 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
174 write_message),
175 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
176 &are_all_peers_started),
177 GNUNET_TRANSPORT_cmd_connect_peers_v3 ("connect-peers",
178 "start-peer",
179 "system-create",
180 num,
181 topology),
182 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
183 "start-peer",
184 num),
185 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
186 &message_received),
187 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
188 "start-peer"),
189 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
190 "system-create"),
191 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
192 write_message)
193 };
194
195 GNUNET_TESTING_run (NULL,
196 commands,
197 GNUNET_TIME_UNIT_FOREVER_REL);
198
199}
200
201
202/**
203 * Entry point for the plugin.
204 *
205 * @param cls NULL
206 * @return the exported block API
207 */
208void *
209libgnunet_test_transport_plugin_cmd_udp_backchannel_init (void *cls)
210{
211 struct GNUNET_TESTING_PluginFunctions *api;
212
213 GNUNET_log_setup ("udp-backchannel",
214 "DEBUG",
215 NULL);
216
217 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
218 api->start_testcase = &start_testcase;
219 api->all_peers_started = &all_peers_started;
220 return api;
221}
222
223
224/**
225 * Exit point from the plugin.
226 *
227 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
228 * @return NULL
229 */
230void *
231libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls)
232{
233 struct GNUNET_TESTING_PluginFunctions *api = cls;
234
235 GNUNET_free (api);
236 GNUNET_free (testdir);
237 GNUNET_free (cfgname);
238 return NULL;
239}
240
241
242/* end of plugin_cmd_simple_send.c */