2 This file is part of GNUnet
3 (C) 2008--2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/test_testbed_api_controllerlink.c
23 * @brief testcase for testing controller to subcontroller linking
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testing_lib-new.h"
30 #include "gnunet_testbed_service.h"
33 * Generic logging shortcut
35 #define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
39 * Debug logging shorthand
41 #define LOG_DEBUG(...) \
42 LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
45 * Different stages in testing
56 * Master controller has started
61 * The first slave has been registered at master controller
73 * Host for running master controller
75 static struct GNUNET_TESTBED_Host *host;
78 * The master controller process
80 static struct GNUNET_TESTBED_ControllerProc *cp;
83 * Handle to master controller
85 static struct GNUNET_TESTBED_Controller *mc;
88 * Slave host for running slave controller
90 static struct GNUNET_TESTBED_Host *slave;
93 * Slave host registration handle
95 static struct GNUNET_TESTBED_HostRegistrationHandle *rh;
98 * Handle to global configuration
100 static struct GNUNET_CONFIGURATION_Handle *cfg;
105 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
113 * Global testing status
115 static enum Stage result;
122 * @param tc the task context
125 do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
127 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
128 GNUNET_SCHEDULER_cancel (abort_task);
130 GNUNET_TESTBED_host_destroy (slave);
132 GNUNET_TESTBED_host_destroy (host);
134 GNUNET_TESTBED_controller_disconnect (mc);
136 GNUNET_CONFIGURATION_destroy (cfg);
138 GNUNET_TESTBED_controller_stop (cp);
140 GNUNET_TESTBED_cancel_registration (rh);
146 * abort task to run on test timed out
149 * @param tc the task context
152 do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
154 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
155 abort_task = GNUNET_SCHEDULER_NO_TASK;
156 do_shutdown (cls, tc);
161 * Signature of the event handler function called by the
162 * respective event controller.
165 * @param event information about the event
168 controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
175 * Callback which will be called to after a host registration succeeded or failed
177 * @param cls the host which has been registered
178 * @param emsg the error message; NULL if host registration is successful
181 registration_cont (void *cls, const char *emsg)
187 GNUNET_assert (NULL == emsg);
188 GNUNET_assert (NULL != mc);
189 result = SLAVE1_REGISTERED;
190 GNUNET_assert (NULL != cfg);
191 GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES);
193 GNUNET_SCHEDULER_add_delayed
194 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
199 case SLAVE1_REGISTERED:
205 * Callback to signal successfull startup of the controller process
207 * @param cls the closure from GNUNET_TESTBED_controller_start()
208 * @param cfg the configuration with which the controller has been started;
209 * NULL if status is not GNUNET_OK
210 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
211 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
214 status_cb (void *cls,
215 const struct GNUNET_CONFIGURATION_Handle *config, int status)
220 GNUNET_assert (GNUNET_OK == status);
222 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
223 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
224 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
225 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
226 mc = GNUNET_TESTBED_controller_connect (config, host, event_mask,
227 &controller_cb, NULL);
228 GNUNET_assert (NULL != mc);
229 result = MASTER_STARTED;
230 slave = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, 0);
231 GNUNET_assert (NULL != slave);
232 rh = GNUNET_TESTBED_register_host (mc, slave, ®istration_cont, NULL);
233 GNUNET_assert (NULL != rh);
245 * @param args arguments passed to GNUNET_PROGRAM_run
246 * @param cfgfile the path to configuration file
247 * @param cfg the configuration file handle
250 run (void *cls, char *const *args, const char *cfgfile,
251 const struct GNUNET_CONFIGURATION_Handle *config)
253 host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
254 GNUNET_assert (NULL != host);
255 cfg = GNUNET_CONFIGURATION_dup (config);
257 GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb, NULL);
258 abort_task = GNUNET_SCHEDULER_add_delayed
259 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30),
267 int main (int argc, char **argv)
271 char *const argv2[] = { "test_testbed_api_controllerlink",
272 "-c", "test_testbed_api.conf",
275 struct GNUNET_GETOPT_CommandLineOption options[] = {
276 GNUNET_GETOPT_OPTION_END
279 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
280 "test_testbed_api_controllerlink", "nohelp", options, &run,
282 if ((GNUNET_OK != ret) || (SUCCESS != result))