diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-14 13:24:09 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-14 13:24:09 +0000 |
commit | 42adbe53cd7a0172ffe755be5e9edb0a0207b739 (patch) | |
tree | 30ef8b08231f83412f4e96e66d017f6057c51015 /src/testbed | |
parent | b70a0e8413db368d433ff4efb501ba2b8ae40cc7 (diff) | |
download | gnunet-42adbe53cd7a0172ffe755be5e9edb0a0207b739.tar.gz gnunet-42adbe53cd7a0172ffe755be5e9edb0a0207b739.zip |
fixes
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/Makefile.am | 7 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 5 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_2peers.c | 2 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_controllerlink.c | 306 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 4 |
5 files changed, 320 insertions, 4 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 6ce57330e..0e703750b 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -69,6 +69,7 @@ libgnunettestbed_la_LDFLAGS = \ | |||
69 | 69 | ||
70 | check_PROGRAMS = \ | 70 | check_PROGRAMS = \ |
71 | test_testbed_api_hosts \ | 71 | test_testbed_api_hosts \ |
72 | test_testbed_api_controllerlink \ | ||
72 | test_testbed_api_2peers \ | 73 | test_testbed_api_2peers \ |
73 | test_testbed_api \ | 74 | test_testbed_api \ |
74 | test_testbed_api_operations \ | 75 | test_testbed_api_operations \ |
@@ -109,6 +110,12 @@ test_testbed_api_operations_LDADD = \ | |||
109 | $(top_builddir)/src/util/libgnunetutil.la \ | 110 | $(top_builddir)/src/util/libgnunetutil.la \ |
110 | libgnunettestbed.la | 111 | libgnunettestbed.la |
111 | 112 | ||
113 | test_testbed_api_controllerlink_SOURCES = \ | ||
114 | test_testbed_api_controllerlink.c | ||
115 | test_testbed_api_controllerlink_LDADD = \ | ||
116 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
117 | libgnunettestbed.la | ||
118 | |||
112 | test_gnunet_testbed_helper_SOURCES = \ | 119 | test_gnunet_testbed_helper_SOURCES = \ |
113 | test_gnunet_testbed_helper.c | 120 | test_gnunet_testbed_helper.c |
114 | test_gnunet_testbed_helper_LDADD = \ | 121 | test_gnunet_testbed_helper_LDADD = \ |
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index a9e050344..c333d6b64 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -1112,11 +1112,12 @@ handle_add_host (void *cls, | |||
1112 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); | 1112 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); |
1113 | host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username, | 1113 | host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username, |
1114 | ntohs (msg->ssh_port)); | 1114 | ntohs (msg->ssh_port)); |
1115 | GNUNET_assert (NULL != host); | ||
1115 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1116 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1116 | reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage); | 1117 | reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage); |
1117 | if (GNUNET_OK != host_list_add (host)) | 1118 | if (GNUNET_OK != host_list_add (host)) |
1118 | { | 1119 | { |
1119 | /* We are unable to add a host */ | 1120 | /* We are unable to add a host */ |
1120 | emsg = "A host exists with given host-id"; | 1121 | emsg = "A host exists with given host-id"; |
1121 | LOG_DEBUG ("%s: %u", emsg, host_id); | 1122 | LOG_DEBUG ("%s: %u", emsg, host_id); |
1122 | GNUNET_TESTBED_host_destroy (host); | 1123 | GNUNET_TESTBED_host_destroy (host); |
@@ -1313,7 +1314,7 @@ handle_link_controllers (void *cls, | |||
1313 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1314 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1314 | return; | 1315 | return; |
1315 | } | 1316 | } |
1316 | if (config_size == dest_size) | 1317 | if (config_size != dest_size) |
1317 | { | 1318 | { |
1318 | LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n"); | 1319 | LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n"); |
1319 | GNUNET_free (config); | 1320 | GNUNET_free (config); |
diff --git a/src/testbed/test_testbed_api_2peers.c b/src/testbed/test_testbed_api_2peers.c index 0893afcfb..4c85ce2a3 100644 --- a/src/testbed/test_testbed_api_2peers.c +++ b/src/testbed/test_testbed_api_2peers.c | |||
@@ -404,7 +404,7 @@ int main (int argc, char **argv) | |||
404 | { | 404 | { |
405 | int ret; | 405 | int ret; |
406 | 406 | ||
407 | char *const argv2[] = { "test_testbed_api", | 407 | char *const argv2[] = { "test_testbed_api_2peers", |
408 | "-c", "test_testbed_api.conf", | 408 | "-c", "test_testbed_api.conf", |
409 | NULL | 409 | NULL |
410 | }; | 410 | }; |
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c new file mode 100644 index 000000000..29e5de603 --- /dev/null +++ b/src/testbed/test_testbed_api_controllerlink.c | |||
@@ -0,0 +1,306 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
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 | General Public License for more details. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
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> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testing_lib-new.h" | ||
30 | #include "gnunet_testbed_service.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | /** | ||
39 | * Debug logging shorthand | ||
40 | */ | ||
41 | #define LOG_DEBUG(...) \ | ||
42 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
43 | |||
44 | /** | ||
45 | * Different stages in testing | ||
46 | */ | ||
47 | enum Stage | ||
48 | { | ||
49 | |||
50 | /** | ||
51 | * Initial stage | ||
52 | */ | ||
53 | INIT, | ||
54 | |||
55 | /** | ||
56 | * Master controller has started | ||
57 | */ | ||
58 | MASTER_STARTED, | ||
59 | |||
60 | /** | ||
61 | * The first slave has been registered at master controller | ||
62 | */ | ||
63 | SLAVE1_REGISTERED, | ||
64 | |||
65 | /** | ||
66 | * The second slave has been registered at the master controller | ||
67 | */ | ||
68 | SLAVE2_REGISTERED, | ||
69 | |||
70 | /** | ||
71 | * Final stage | ||
72 | */ | ||
73 | SUCCESS | ||
74 | |||
75 | }; | ||
76 | |||
77 | /** | ||
78 | * Host for running master controller | ||
79 | */ | ||
80 | static struct GNUNET_TESTBED_Host *host; | ||
81 | |||
82 | /** | ||
83 | * The master controller process | ||
84 | */ | ||
85 | static struct GNUNET_TESTBED_ControllerProc *cp; | ||
86 | |||
87 | /** | ||
88 | * Handle to master controller | ||
89 | */ | ||
90 | static struct GNUNET_TESTBED_Controller *mc; | ||
91 | |||
92 | /** | ||
93 | * Slave host for running slave controller | ||
94 | */ | ||
95 | static struct GNUNET_TESTBED_Host *slave; | ||
96 | |||
97 | /** | ||
98 | * Another slave host for running another slave controller | ||
99 | */ | ||
100 | static struct GNUNET_TESTBED_Host *slave2; | ||
101 | |||
102 | /** | ||
103 | * Slave host registration handle | ||
104 | */ | ||
105 | static struct GNUNET_TESTBED_HostRegistrationHandle *rh; | ||
106 | |||
107 | /** | ||
108 | * Handle to global configuration | ||
109 | */ | ||
110 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
111 | |||
112 | /** | ||
113 | * Abort task | ||
114 | */ | ||
115 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | ||
116 | |||
117 | /** | ||
118 | * Event mask | ||
119 | */ | ||
120 | uint64_t event_mask; | ||
121 | |||
122 | /** | ||
123 | * Global testing status | ||
124 | */ | ||
125 | static enum Stage result; | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Shutdown nicely | ||
130 | * | ||
131 | * @param cls NULL | ||
132 | * @param tc the task context | ||
133 | */ | ||
134 | static void | ||
135 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
136 | { | ||
137 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
138 | GNUNET_SCHEDULER_cancel (abort_task); | ||
139 | if (NULL != mc) | ||
140 | GNUNET_TESTBED_controller_disconnect (mc); | ||
141 | if (NULL != cp) | ||
142 | GNUNET_TESTBED_controller_stop (cp); | ||
143 | if (NULL != slave2) | ||
144 | GNUNET_TESTBED_host_destroy (slave2); | ||
145 | if (NULL != slave) | ||
146 | GNUNET_TESTBED_host_destroy (slave); | ||
147 | if (NULL != host) | ||
148 | GNUNET_TESTBED_host_destroy (host); | ||
149 | if (NULL != cfg) | ||
150 | GNUNET_CONFIGURATION_destroy (cfg); | ||
151 | if (NULL != rh) | ||
152 | GNUNET_TESTBED_cancel_registration (rh); | ||
153 | |||
154 | } | ||
155 | |||
156 | |||
157 | /** | ||
158 | * abort task to run on test timed out | ||
159 | * | ||
160 | * @param cls NULL | ||
161 | * @param tc the task context | ||
162 | */ | ||
163 | static void | ||
164 | do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
165 | { | ||
166 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | ||
167 | abort_task = GNUNET_SCHEDULER_NO_TASK; | ||
168 | do_shutdown (cls, tc); | ||
169 | } | ||
170 | |||
171 | |||
172 | /** | ||
173 | * Signature of the event handler function called by the | ||
174 | * respective event controller. | ||
175 | * | ||
176 | * @param cls closure | ||
177 | * @param event information about the event | ||
178 | */ | ||
179 | static void | ||
180 | controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) | ||
181 | { | ||
182 | GNUNET_assert (0); | ||
183 | } | ||
184 | |||
185 | |||
186 | /** | ||
187 | * Callback which will be called to after a host registration succeeded or failed | ||
188 | * | ||
189 | * @param cls the host which has been registered | ||
190 | * @param emsg the error message; NULL if host registration is successful | ||
191 | */ | ||
192 | static void | ||
193 | registration_cont (void *cls, const char *emsg) | ||
194 | { | ||
195 | rh = NULL; | ||
196 | switch (result) | ||
197 | { | ||
198 | case MASTER_STARTED: | ||
199 | GNUNET_assert (NULL == emsg); | ||
200 | result = SLAVE1_REGISTERED; | ||
201 | slave2 = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, 0); | ||
202 | GNUNET_assert (NULL != slave2); | ||
203 | rh = GNUNET_TESTBED_register_host (mc, slave2, ®istration_cont, NULL); | ||
204 | GNUNET_assert (NULL != rh); | ||
205 | break; | ||
206 | case SLAVE1_REGISTERED: | ||
207 | GNUNET_assert (NULL == emsg); | ||
208 | GNUNET_assert (NULL != mc); | ||
209 | result = SLAVE2_REGISTERED; | ||
210 | GNUNET_assert (NULL != cfg); | ||
211 | GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES); | ||
212 | //GNUNET_TESTBED_controller_link (mc, host, slave | ||
213 | result = SUCCESS; | ||
214 | GNUNET_SCHEDULER_add_delayed | ||
215 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3), | ||
216 | &do_shutdown, NULL); | ||
217 | break; | ||
218 | case INIT: | ||
219 | case SUCCESS: | ||
220 | case SLAVE2_REGISTERED: | ||
221 | GNUNET_assert (0); | ||
222 | } | ||
223 | } | ||
224 | |||
225 | /** | ||
226 | * Callback to signal successfull startup of the controller process | ||
227 | * | ||
228 | * @param cls the closure from GNUNET_TESTBED_controller_start() | ||
229 | * @param cfg the configuration with which the controller has been started; | ||
230 | * NULL if status is not GNUNET_OK | ||
231 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, | ||
232 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | ||
233 | */ | ||
234 | static void | ||
235 | status_cb (void *cls, | ||
236 | const struct GNUNET_CONFIGURATION_Handle *config, int status) | ||
237 | { | ||
238 | switch (result) | ||
239 | { | ||
240 | case INIT: | ||
241 | GNUNET_assert (GNUNET_OK == status); | ||
242 | event_mask = 0; | ||
243 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | ||
244 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | ||
245 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | ||
246 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
247 | mc = GNUNET_TESTBED_controller_connect (config, host, event_mask, | ||
248 | &controller_cb, NULL); | ||
249 | GNUNET_assert (NULL != mc); | ||
250 | result = MASTER_STARTED; | ||
251 | slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, 0); | ||
252 | GNUNET_assert (NULL != slave); | ||
253 | rh = GNUNET_TESTBED_register_host (mc, slave, ®istration_cont, NULL); | ||
254 | GNUNET_assert (NULL != rh); | ||
255 | break; | ||
256 | default: | ||
257 | GNUNET_assert (0); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | |||
262 | /** | ||
263 | * Main run function. | ||
264 | * | ||
265 | * @param cls NULL | ||
266 | * @param args arguments passed to GNUNET_PROGRAM_run | ||
267 | * @param cfgfile the path to configuration file | ||
268 | * @param cfg the configuration file handle | ||
269 | */ | ||
270 | static void | ||
271 | run (void *cls, char *const *args, const char *cfgfile, | ||
272 | const struct GNUNET_CONFIGURATION_Handle *config) | ||
273 | { | ||
274 | host = GNUNET_TESTBED_host_create (NULL, NULL, 0); | ||
275 | GNUNET_assert (NULL != host); | ||
276 | cfg = GNUNET_CONFIGURATION_dup (config); | ||
277 | cp = | ||
278 | GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb, NULL); | ||
279 | abort_task = GNUNET_SCHEDULER_add_delayed | ||
280 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30), | ||
281 | &do_abort, NULL); | ||
282 | } | ||
283 | |||
284 | |||
285 | /** | ||
286 | * Main function | ||
287 | */ | ||
288 | int main (int argc, char **argv) | ||
289 | { | ||
290 | int ret; | ||
291 | |||
292 | char *const argv2[] = { "test_testbed_api_controllerlink", | ||
293 | "-c", "test_testbed_api.conf", | ||
294 | NULL | ||
295 | }; | ||
296 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
297 | GNUNET_GETOPT_OPTION_END | ||
298 | }; | ||
299 | result = INIT; | ||
300 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
301 | "test_testbed_api_controllerlink", "nohelp", options, &run, | ||
302 | NULL); | ||
303 | if ((GNUNET_OK != ret) || (SUCCESS != result)) | ||
304 | return 1; | ||
305 | return 0; | ||
306 | } | ||
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 597b7f348..691ab5a17 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -1005,7 +1005,7 @@ GNUNET_TESTBED_controller_start (const char *controller_ip, | |||
1005 | if (NULL == username) | 1005 | if (NULL == username) |
1006 | GNUNET_asprintf (&cp->dst, "%s", hostname); | 1006 | GNUNET_asprintf (&cp->dst, "%s", hostname); |
1007 | else | 1007 | else |
1008 | GNUNET_asprintf (&cp->dst, "%s@%s", hostname, username); | 1008 | GNUNET_asprintf (&cp->dst, "%s@%s", username, hostname); |
1009 | argp = 0; | 1009 | argp = 0; |
1010 | remote_args[argp++] = "ssh"; | 1010 | remote_args[argp++] = "ssh"; |
1011 | remote_args[argp++] = "-p"; | 1011 | remote_args[argp++] = "-p"; |
@@ -1126,6 +1126,8 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg | |||
1126 | } | 1126 | } |
1127 | } | 1127 | } |
1128 | GNUNET_assert (NULL != host); | 1128 | GNUNET_assert (NULL != host); |
1129 | GNUNET_TESTBED_mark_host_registered_at_ (host, controller); | ||
1130 | controller->host = host; | ||
1129 | controller->opq_peer_create = | 1131 | controller->opq_peer_create = |
1130 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1132 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1131 | max_parallel_peer_create); | 1133 | max_parallel_peer_create); |