GNUnet 0.24.1-15-gab6ed22f1
plugin_testing_transport_nat_upnp.c File Reference
#include "platform.h"
#include "gnunet_testing_barrier.h"
#include "gnunet_testing_netjail_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_transport_application_service.h"
#include "transport-testing2.h"
#include "transport-testing-cmds.h"
Include dependency graph for plugin_testing_transport_nat_upnp.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 
#define BASE_DIR   "testdir"
 
#define TOPOLOGY_CONFIG   "test_transport_simple_send_topo.conf"
 
#define TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
 

Functions

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. More...
 
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. More...
 
struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers ()
 
static void handle_result (void *cls, enum GNUNET_GenericReturnValue rv)
 Function called with the final result of the test. More...
 
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. More...
 
static struct GNUNET_TESTING_Interpreterstart_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. More...
 
void * libgnunet_test_transport_plugin_cmd_nat_upnp_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_test_transport_plugin_cmd_nat_upnp_done (void *cls)
 Exit point from the plugin. More...
 

Variables

static struct GNUNET_TESTING_Command block_send
 
static struct GNUNET_TESTING_Command block_receive
 
static struct GNUNET_TESTING_Command connect_peers
 
static struct GNUNET_TESTING_Command local_prepared
 
static struct GNUNET_TESTING_Interpreteris
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 38 of file plugin_testing_transport_nat_upnp.c.

◆ BASE_DIR

#define BASE_DIR   "testdir"

Definition at line 40 of file plugin_testing_transport_nat_upnp.c.

◆ TOPOLOGY_CONFIG

#define TOPOLOGY_CONFIG   "test_transport_simple_send_topo.conf"

Definition at line 42 of file plugin_testing_transport_nat_upnp.c.

◆ TIMEOUT

Definition at line 44 of file plugin_testing_transport_nat_upnp.c.

Function Documentation

◆ check_test()

static int check_test ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.

Definition at line 62 of file plugin_testing_transport_nat_upnp.c.

64{
65 return GNUNET_OK;
66}
@ GNUNET_OK

References GNUNET_OK.

◆ handle_test()

static void handle_test ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.

Definition at line 75 of file plugin_testing_transport_nat_upnp.c.

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}
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_TESTING_Command block_receive
State each asynchronous command must have in its closure.

References block_receive, GNUNET_assert, GNUNET_TESTING_async_fail(), and GNUNET_TESTING_async_finish().

Here is the call graph for this function:

◆ get_waiting_for_barriers()

struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers ( )

Definition at line 91 of file plugin_testing_transport_nat_upnp.c.

92{
93 struct GNUNET_TESTING_BarrierList*barriers;
94 struct GNUNET_TESTING_BarrierListEntry *ble;
95
96 barriers = GNUNET_new (struct GNUNET_TESTING_BarrierList);
97 ble = GNUNET_new (struct GNUNET_TESTING_BarrierListEntry);
98 ble->barrier_name = "ready-to-connect";
99 ble->expected_reaches = 1;
100 GNUNET_CONTAINER_DLL_insert (barriers->head,
101 barriers->tail,
102 ble);
103
104 ble = GNUNET_new (struct GNUNET_TESTING_BarrierListEntry);
105 ble->barrier_name = "test-case-finished";
106 ble->expected_reaches = 1;
107 GNUNET_CONTAINER_DLL_insert (barriers->head,
108 barriers->tail,
109 ble);
110 return barriers;
111}
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References GNUNET_CONTAINER_DLL_insert, and GNUNET_new.

Referenced by libgnunet_test_transport_plugin_cmd_nat_upnp_init().

Here is the caller graph for this function:

◆ handle_result()

static void handle_result ( void *  cls,
enum GNUNET_GenericReturnValue  rv 
)
static

Function called with the final result of the test.

Parameters
clsthe struct MainParams
rvGNUNET_OK if the test passed

Definition at line 121 of file plugin_testing_transport_nat_upnp.c.

123{
124 struct TestState *ts = cls;
125
127 "Local test exits with status %d\n",
128 rv);
129
130 ts->finished_cb (rv);
131 GNUNET_free (ts->testdir);
132 GNUNET_free (ts->cfgname);
134 GNUNET_free (ts);
135}
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
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_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.

References TestState::cfgname, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_TESTING_free_topology(), TestState::testdir, and TestState::topology.

Referenced by start_testcase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_connect()

static void * notify_connect ( struct GNUNET_TESTING_Interpreter is,
const struct GNUNET_PeerIdentity peer 
)
static

Callback from start peer cmd for signaling a peer got connected.

Definition at line 143 of file plugin_testing_transport_nat_upnp.c.

145{
146 const struct ConnectPeersState *cps;
147 const struct GNUNET_TESTING_Command *cmd;
148
150 "connect-peers");
151 GNUNET_TRANSPORT_TESTING_get_trait_connect_peer_state (cmd,
152 &cps);
153 void *ret = NULL;
154
155 cps->notify_connect (is,
156 peer);
157 return ret;
158}
static int ret
Final status code.
Definition: gnunet-arm.c:93
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
static struct GNUNET_TESTING_Interpreter * is
Struct to store information needed in callbacks.
GNUNET_TESTING_notify_connect_cb notify_connect
A command to be run by the interpreter.

References GNUNET_TESTING_interpreter_lookup_command(), is, ConnectPeersState::notify_connect, and ret.

Referenced by start_testcase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_testcase()

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 
)
static

Function to start a local test case.

Parameters
write_messageCallback to send a message to the master loop.
router_ipGlobal address of the network namespace.
node_ipThe IP address of the node.
mThe number of the node in a network namespace.
nThe number of the network namespace.
local_mThe number of nodes in a network namespace.
topology_dataA file name for the file containing the topology configuration, or a string containing the topology configuration.
read_fileIf read_file is GNUNET_YES this string is the filename for the topology configuration, if read_file is GNUNET_NO the string contains the topology configuration.
finish_cbCallback function which writes a message from the helper process running on a netjail node to the master process * signaling that the test case running on the netjail node finished.
Returns
Returns the struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node.

Definition at line 179 of file plugin_testing_transport_nat_upnp.c.

188{
189
190 unsigned int n_int;
191 unsigned int m_int;
192 unsigned int local_m_int;
193 unsigned int num;
194 struct TestState *ts = GNUNET_new (struct TestState);
195 struct GNUNET_TESTING_NetjailTopology *topology;
196 unsigned int sscanf_ret = 0;
197
198 ts->finished_cb = finished_cb;
200 "n %s m %s\n",
201 n,
202 m);
203
204 if (GNUNET_YES == *read_file)
205 {
207 "read from file\n");
208 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
209 }
210 else
211 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
212
213 ts->topology = topology;
214
215 errno = 0;
216 sscanf_ret = sscanf (m, "%u", &m_int);
217 if (errno != 0)
218 {
220 }
221 GNUNET_assert (0 < sscanf_ret);
222 errno = 0;
223 sscanf_ret = sscanf (n, "%u", &n_int);
224 if (errno != 0)
225 {
227 }
228 GNUNET_assert (0 < sscanf_ret);
229 errno = 0;
230 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
231 if (errno != 0)
232 {
234 }
235 GNUNET_assert (0 < sscanf_ret);
236
237 if (0 == n_int)
238 num = m_int;
239 else
240 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
241
242 block_send = GNUNET_TESTING_cmd_block_until_external_trigger (
243 "block");
244 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
245 "block-receive");
247 "start-peer",
248 "system-create",
249 num,
250 topology,
251 0,
252 GNUNET_YES);
253 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
254 "local-test-prepared",
256
257
259 "test_transport_api_tcp_node1.conf");
260
262 "plugin cfgname: %s\n",
263 ts->cfgname);
264
266 "node ip: %s\n",
267 node_ip);
268
270 "%s%s%s",
271 BASE_DIR,
272 m,
273 n);
274
279 ts),
281 };
282
284 GNUNET_TESTING_cmd_system_create ("system-create",
285 ts->testdir),
287 "system-create",
288 num,
289 node_ip,
290 handlers,
291 ts->cfgname,
293 GNUNET_NO),
294 GNUNET_TESTING_cmd_barrier_reached ("ready-to-connect-reached",
295 "ready-to-connect",
296 GNUNET_NO,
297 num,
298 GNUNET_NO,
302 "start-peer",
303 "system-create",
304 num,
305 topology),
307 GNUNET_TESTING_cmd_barrier_reached ("test-case-finished-reached",
308 "test-case-finished",
309 GNUNET_NO,
310 num,
311 GNUNET_NO,
314 "start-peer"),
315 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
316 "system-create"),
318 };
319
320 ts->write_message = write_message;
321
323 TIMEOUT,
325 ts);
326 return is;
327}
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 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.
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.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached(const char *label, const char *barrier_label)
If this command is executed the the process is signaling the master process that it reached a barrier...
@ GNUNET_YES
@ GNUNET_NO
#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
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71
static struct GNUNET_TESTING_Command block_send
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 * notify_connect(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer)
Callback from start peer cmd for signaling a peer got connected.
#define LOG(kind,...)
Generic logging shortcut.
Message handler for a specific message type.
Topology of our netjail setup.
unsigned int nodes_x
Number of global known nodes.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple(const char *label, const char *start_peer_label, const char *create_label, uint32_t num)
Create command.
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().

References BASE_DIR, block_receive, block_send, TestState::cfgname, commands, connect_peers, finished_cb(), GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_new, GNUNET_NO, GNUNET_TESTING_cmd_barrier_reached(), GNUNET_TESTING_cmd_end(), GNUNET_TESTING_run(), GNUNET_TRANSPORT_cmd_connect_peers(), GNUNET_TRANSPORT_cmd_send_simple(), GNUNET_TRANSPORT_cmd_start_peer(), GNUNET_TRANSPORT_cmd_stop_peer(), GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, GNUNET_YES, handle_result(), handlers, is, local_prepared, LOG, m, GNUNET_TESTING_NetjailTopology::nodes_x, notify_connect(), read_file(), TestState::testdir, TIMEOUT, TestState::topology, and write_message().

Referenced by libgnunet_test_transport_plugin_cmd_nat_upnp_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_test_transport_plugin_cmd_nat_upnp_init()

void * libgnunet_test_transport_plugin_cmd_nat_upnp_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 337 of file plugin_testing_transport_nat_upnp.c.

338{
340
341 GNUNET_log_setup ("simple-send",
342 "DEBUG",
343 NULL);
344
347 api->get_waiting_for_barriers = get_waiting_for_barriers;
348 return api;
349}
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers()
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.
The plugin API every test case plugin has to implement.
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.

References get_waiting_for_barriers(), GNUNET_log_setup(), GNUNET_new, start_testcase(), and GNUNET_TESTING_PluginFunctions::start_testcase.

Here is the call graph for this function:

◆ libgnunet_test_transport_plugin_cmd_nat_upnp_done()

void * libgnunet_test_transport_plugin_cmd_nat_upnp_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from #libgnunet_test_transport_plugin_nat_upnp_init
Returns
NULL

Definition at line 359 of file plugin_testing_transport_nat_upnp.c.

360{
362
363 GNUNET_free (api);
364 return NULL;
365}
void * cls
Closure to pass to start_testcase.

References GNUNET_TESTING_PluginFunctions::cls, and GNUNET_free.

Variable Documentation

◆ block_send

struct GNUNET_TESTING_Command block_send
static

Definition at line 46 of file plugin_testing_transport_nat_upnp.c.

Referenced by start_testcase().

◆ block_receive

struct GNUNET_TESTING_Command block_receive
static

Definition at line 48 of file plugin_testing_transport_nat_upnp.c.

Referenced by handle_test(), and start_testcase().

◆ connect_peers

struct GNUNET_TESTING_Command connect_peers
static

Definition at line 50 of file plugin_testing_transport_nat_upnp.c.

Referenced by start_testcase().

◆ local_prepared

struct GNUNET_TESTING_Command local_prepared
static

Definition at line 52 of file plugin_testing_transport_nat_upnp.c.

Referenced by start_testcase().

◆ is

struct GNUNET_TESTING_Interpreter* is
static

Definition at line 54 of file plugin_testing_transport_nat_upnp.c.

Referenced by notify_connect(), and start_testcase().