GNUnet 0.24.1-12-gebf1afa89
plugin_testing_transport_nat_mapping.c
Go to the documentation of this file.
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
26#include "platform.h"
27#include "gnunet_testing_barrier.h"
28#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_util_lib.h"
31#include "transport-testing2.h"
33#include "gnunet_testing_barrier.h"
34
38#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
39
40#define BASE_DIR "testdir"
41
42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
43
44#define ROUTER_BASE_IP "92.68.150."
45
47
49
51
53
55
61static int
62check_test (void *cls,
63 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
64{
65 return GNUNET_OK;
66}
67
68
74static void
75handle_test (void *cls,
76 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
77{
79
80 GNUNET_TESTING_get_trait_async_context (&block_receive,
81 &ac);
82 GNUNET_assert (NULL != ac);
83 if (NULL == ac->cont)
85 else
87}
88
89
90struct GNUNET_TESTING_BarrierList *
92{
93 //No Barrier
94 return GNUNET_new (struct GNUNET_TESTING_BarrierList);
95}
96
97
102static void
104{
106
107 GNUNET_TESTING_get_trait_async_context (&block_send,
108 &ac);
109 GNUNET_assert (NULL != ac);
110 if (NULL == ac->cont)
112 else
114}
115
116
123static void
124handle_result (void *cls,
126{
127 struct TestState *ts = cls;
128
130 "Local test exits with status %d\n",
131 rv);
132
133 ts->finished_cb (rv);
134 GNUNET_free (ts->testdir);
135 GNUNET_free (ts->cfgname);
137 GNUNET_free (ts);
138}
139
140
145static void *
147 const struct GNUNET_PeerIdentity *peer)
148{
149 const struct ConnectPeersState *cps;
150 const struct GNUNET_TESTING_Command *cmd;
151
153 "connect-peers");
154 GNUNET_TRANSPORT_TESTING_get_trait_connect_peer_state (cmd,
155 &cps);
156 void *ret = NULL;
157
158 cps->notify_connect (is,
159 peer);
160 return ret;
161}
162
163
167static void
169{
170 const struct GNUNET_TESTING_LocalPreparedState *lfs;
171
172 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
173 &lfs);
174 GNUNET_assert (NULL != &lfs->ac);
175 if (NULL == lfs->ac.cont)
177 else
179 GNUNET_TESTING_AsyncContext *) &lfs->ac);
180}
181
182
183static void
186 long unsigned int exit_code)
187{
188
189}
190
191
202static struct GNUNET_TESTING_Interpreter *
204 const char *router_ip,
205 const char *node_ip,
206 const char *m,
207 const char *n,
208 const char *local_m,
209 const char *topology_data,
210 unsigned int *read_file,
211 GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
212{
213
214 unsigned int n_int;
215 unsigned int m_int;
216 unsigned int local_m_int;
217 unsigned int num;
218 struct TestState *ts = GNUNET_new (struct TestState);
219 struct GNUNET_TESTING_NetjailTopology *topology;
220 unsigned int sscanf_ret = 0;
221 char **argv = NULL;
222 unsigned int argc = 0;
223 char *dst_ip;
224 char *num_string;
225
226
227
228 ts->finished_cb = finished_cb;
230 "n %s m %s\n",
231 n,
232 m);
233
234 if (GNUNET_YES == *read_file)
235 {
237 "read from file\n");
238 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
239 }
240 else
241 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
242
243 ts->topology = topology;
244
245 errno = 0;
246 sscanf_ret = sscanf (m, "%u", &m_int);
247 if (errno != 0)
248 {
250 }
251 GNUNET_assert (0 < sscanf_ret);
252 errno = 0;
253 sscanf_ret = sscanf (n, "%u", &n_int);
254 if (errno != 0)
255 {
257 }
258 GNUNET_assert (0 < sscanf_ret);
259 errno = 0;
260 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
261 if (errno != 0)
262 {
264 }
265 GNUNET_assert (0 < sscanf_ret);
266
267 if (0 == n_int)
268 num = m_int;
269 else
270 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
271
272 block_send = GNUNET_TESTING_cmd_block_until_external_trigger (
273 "block");
274 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
275 "block-receive");
277 "start-peer",
278 "system-create",
279 num,
280 topology,
281 0,
282 GNUNET_YES);
283 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
284 "local-test-prepared",
286
287
289 "test_transport_api_tcp_node1.conf");
290
292 "plugin cfgname: %s\n",
293 ts->cfgname);
294
296 "node ip: %s\n",
297 node_ip);
298
300 "%s%s%s",
301 BASE_DIR,
302 m,
303 n);
304
309 ts),
311 };
312
314 "num: %u\n",
315 num);
316 GNUNET_asprintf (&num_string,
317 "%u",
318 num);
319 GNUNET_array_append (argv, argc, "7777");
320 GNUNET_array_append (argv, argc, num_string);
321 if (1 == num )
322 {
323 GNUNET_asprintf (&dst_ip,
324 ROUTER_BASE_IP "%u",
325 num + 1);
326 GNUNET_array_append (argv, argc, dst_ip);
327 }
328 else
329 {
330 GNUNET_asprintf (&dst_ip,
331 ROUTER_BASE_IP "%u",
332 num - 1);
333 GNUNET_array_append (argv, argc, dst_ip);
334 }
335
337 "dst_ip %s\n",
338 dst_ip);
340 GNUNET_TESTING_cmd_system_create ("system-create",
341 ts->testdir),
343 "system-create",
344 num,
345 node_ip,
346 handlers,
347 ts->cfgname,
349 GNUNET_NO),
350 GNUNET_TESTING_cmd_exec_bash_script ("nat_node_test",
351 "nat_node_test.sh",
352 argv,
353 argc,
355 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
361 "start-peer"),
362 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
363 "system-create"),
365 };
366
367 ts->write_message = write_message;
368
370 TIMEOUT,
372 ts);
373 GNUNET_free (num_string);
374 GNUNET_free (dst_ip);
375 return is;
376}
377
378
385void *
387{
389
390 GNUNET_log_setup ("simple-send",
391 "DEBUG",
392 NULL);
393
396 api->all_peers_started = &all_peers_started;
397 api->all_local_tests_prepared = all_local_tests_prepared;
398 api->get_waiting_for_barriers = get_waiting_for_barriers;
399 return api;
400}
401
402
409void *
411{
413
414 GNUNET_free (api);
415 return NULL;
416}
417
418
419/* end of plugin_cmd_nat_mapping.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static int ret
Final status code.
Definition: gnunet-arm.c:93
static void write_message(const struct GNUNET_MessageHeader *message)
Callback to write a message to the parent process.
static void finished_cb(void *cls, enum GNUNET_GenericReturnValue rv)
static struct VoipCommand commands[]
List of supported commands.
static uint32_t type
Type string converted to DNS type value.
static int exit_code
Global exit code.
Definition: gnunet-qr.c:43
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
struct GNUNET_TESTING_Interpreter * GNUNET_TESTING_run(const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
Run the testsuite.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
Bandwidth allocation API for applications to interact with.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
GNUNET_OS_ProcessStatusType
Process status types.
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71
static void child_completed_callback(void *cls, enum GNUNET_OS_ProcessStatusType type, long unsigned int exit_code)
static struct GNUNET_TESTING_Command block_receive
static struct GNUNET_TESTING_Command block_send
void * libgnunet_test_transport_plugin_cmd_nat_mapping_done(void *cls)
Exit point from the plugin.
static void handle_result(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
static struct GNUNET_TESTING_Command local_prepared
static struct GNUNET_TESTING_Command connect_peers
static void all_local_tests_prepared()
Callback to set the flag indicating all peers are prepared to finish.
static void * notify_connect(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer)
Callback from start peer cmd for signaling a peer got connected.
struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers()
static int check_test(void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.
static void handle_test(void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.
static struct GNUNET_TESTING_Interpreter * is
void * libgnunet_test_transport_plugin_cmd_nat_mapping_init(void *cls)
Entry point for the plugin.
#define LOG(kind,...)
Generic logging shortcut.
static void all_peers_started()
Callback to set the flag indicating all peers started.
static struct GNUNET_TESTING_Interpreter * start_testcase(GNUNET_TESTING_cmd_helper_write_cb write_message, const char *router_ip, const char *node_ip, const char *m, const char *n, const char *local_m, const char *topology_data, unsigned int *read_file, GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
Function to start a local test case.
Struct to store information needed in callbacks.
GNUNET_TESTING_notify_connect_cb notify_connect
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
State each asynchronous command must have in its closure.
A command to be run by the interpreter.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Topology of our netjail setup.
unsigned int nodes_x
Number of global known nodes.
The plugin API every test case plugin has to implement.
void * cls
Closure to pass to start_testcase.
struct GNUNET_TESTING_Interpreter *(* start_testcase)(void *cls, const char *topology_data, uint32_t barrier_count, const struct GNUNET_ShortHashCode *barriers, GNUNET_TESTING_cmd_helper_write_cb write_message, GNUNET_TESTING_ResultCallback finish_cb, void *finish_cb_cls)
Function to be implemented for each test case plugin which starts the test case on a netjail node.
char * cfgname
The name for the configuration file of the specific node.
char * testdir
The name for a specific test environment directory.
struct GNUNET_TESTING_NetjailTopology * topology
The complete topology information.
void(* GNUNET_TESTING_cmd_helper_write_cb)(const struct GNUNET_MessageHeader *message)
Callback function to write messages from the helper process running on a netjail node to the master p...
void GNUNET_TESTING_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_stop_peer(const char *label, const char *start_label)
Create command.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers(const char *label, const char *start_peer_label, const char *create_label, uint32_t num, struct GNUNET_TESTING_NetjailTopology *topology, unsigned int additional_connects, unsigned int wait_for_connect)
Create command.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_start_peer(const char *label, const char *system_label, uint32_t no, const char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, const char *cfgname, GNUNET_TRANSPORT_notify_connect_cb notify_connect, unsigned int broadcast)
Create command.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().