test_testbed_api_controllerlink.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /*
  2. This file is part of GNUnet
  3. (C) 2008--2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file testbed/test_testbed_api_controllerlink.c
  19. * @brief testcase for testing controller to subcontroller linking
  20. * @author Sree Harsha Totakura <sreeharsha@totakura.in>
  21. */
  22. /**
  23. * The controller architecture we try to achieve in this test case:
  24. *
  25. * Master Controller
  26. * // \\
  27. * // \\
  28. * Slave Controller 1---------Slave Controller 3
  29. * ||
  30. * ||
  31. * Slave Controller 2
  32. */
  33. #include "platform.h"
  34. #include "gnunet_util_lib.h"
  35. #include "gnunet_testing_lib.h"
  36. #include "gnunet_testbed_service.h"
  37. /**
  38. * Generic logging shortcut
  39. */
  40. #define LOG(kind,...) \
  41. GNUNET_log (kind, __VA_ARGS__)
  42. /**
  43. * Debug logging shorthand
  44. */
  45. #define LOG_DEBUG(...) \
  46. LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
  47. /**
  48. * Different stages in testing
  49. */
  50. enum Stage
  51. {
  52. /**
  53. * Initial stage
  54. */
  55. INIT,
  56. /**
  57. * Master controller has started
  58. */
  59. MASTER_STARTED,
  60. /**
  61. * A peer has been created on master
  62. */
  63. MASTER_PEER_CREATE_SUCCESS,
  64. /**
  65. * Peer on master controller has been started successfully.
  66. */
  67. MASTER_PEER_START_SUCCESS,
  68. /**
  69. * The first slave has been registered at master controller
  70. */
  71. SLAVE1_REGISTERED,
  72. /**
  73. * The second slave has been registered at the master controller
  74. */
  75. SLAVE2_REGISTERED,
  76. /**
  77. * Link from master to slave 1 has been successfully created
  78. */
  79. SLAVE1_LINK_SUCCESS,
  80. /**
  81. * Peer create on slave 1 successful
  82. */
  83. SLAVE1_PEER_CREATE_SUCCESS,
  84. /**
  85. * Peer startup on slave 1 successful
  86. */
  87. SLAVE1_PEER_START_SUCCESS,
  88. /**
  89. * Link from slave 1 to slave 2 has been successfully created.
  90. */
  91. SLAVE2_LINK_SUCCESS,
  92. /**
  93. * Peer create on slave 2 successful
  94. */
  95. SLAVE2_PEER_CREATE_SUCCESS,
  96. /**
  97. * Peer on slave 1 successfully stopped
  98. */
  99. SLAVE1_PEER_STOP_SUCCESS,
  100. /**
  101. * Peer startup on slave 2 successful
  102. */
  103. SLAVE2_PEER_START_SUCCESS,
  104. /**
  105. * Try to connect peers on master and slave 2.
  106. */
  107. MASTER_SLAVE2_PEERS_CONNECTED,
  108. /**
  109. * Slave 3 has successfully registered
  110. */
  111. SLAVE3_REGISTERED,
  112. /**
  113. * Slave 3 has successfully started
  114. */
  115. SLAVE3_STARTED,
  116. /**
  117. * Peer created on slave 3
  118. */
  119. SLAVE3_PEER_CREATE_SUCCESS,
  120. /**
  121. * Peer started at slave 3
  122. */
  123. SLAVE3_PEER_START_SUCCESS,
  124. /**
  125. * Try to connect peers on slave2 and slave3
  126. */
  127. SLAVE2_SLAVE3_PEERS_CONNECTED,
  128. /**
  129. * Peer on slave 2 successfully stopped
  130. */
  131. SLAVE2_PEER_STOP_SUCCESS,
  132. /**
  133. * Peer destroy on slave 1 successful
  134. */
  135. SLAVE1_PEER_DESTROY_SUCCESS,
  136. /**
  137. * Peer destory on slave 2 successful
  138. */
  139. SLAVE2_PEER_DESTROY_SUCCESS,
  140. /**
  141. * The configuration of slave 3 is acquired
  142. */
  143. SLAVE3_GET_CONFIG_SUCCESS,
  144. /**
  145. * Slave 1 has linked to slave 3;
  146. */
  147. SLAVE3_LINK_SUCCESS,
  148. /**
  149. * Master peer destoryed. Destory slave 3 peer
  150. */
  151. MASTER_PEER_DESTROY_SUCCESS,
  152. /**
  153. * Slave 3 peer destroyed. Mark test as success
  154. */
  155. SUCCESS,
  156. /**
  157. * Marks test as skipped
  158. */
  159. SKIP
  160. };
  161. /**
  162. * Host for running master controller
  163. */
  164. static struct GNUNET_TESTBED_Host *host;
  165. /**
  166. * The master controller process
  167. */
  168. static struct GNUNET_TESTBED_ControllerProc *cp;
  169. /**
  170. * Handle to master controller
  171. */
  172. static struct GNUNET_TESTBED_Controller *mc;
  173. /**
  174. * Slave host for running slave controller
  175. */
  176. static struct GNUNET_TESTBED_Host *slave;
  177. /**
  178. * Another slave host for running another slave controller
  179. */
  180. static struct GNUNET_TESTBED_Host *slave2;
  181. /**
  182. * Host for slave 3
  183. */
  184. static struct GNUNET_TESTBED_Host *slave3;
  185. /**
  186. * Slave host registration handle
  187. */
  188. static struct GNUNET_TESTBED_HostRegistrationHandle *rh;
  189. /**
  190. * Handle to global configuration
  191. */
  192. static struct GNUNET_CONFIGURATION_Handle *cfg;
  193. /**
  194. * Configuration of slave 3 controller
  195. */
  196. static struct GNUNET_CONFIGURATION_Handle *cfg3;
  197. /**
  198. * Abort task
  199. */
  200. static GNUNET_SCHEDULER_TaskIdentifier abort_task;
  201. /**
  202. * Operation handle for linking controllers
  203. */
  204. static struct GNUNET_TESTBED_Operation *op;
  205. /**
  206. * Handle to peer started at slave 1
  207. */
  208. static struct GNUNET_TESTBED_Peer *slave1_peer;
  209. /**
  210. * Handle to peer started at slave 2
  211. */
  212. static struct GNUNET_TESTBED_Peer *slave2_peer;
  213. /**
  214. * Handle to peer started at slave 2
  215. */
  216. static struct GNUNET_TESTBED_Peer *slave3_peer;
  217. /**
  218. * Handle to a peer started at master controller
  219. */
  220. static struct GNUNET_TESTBED_Peer *master_peer;
  221. /**
  222. * The handle for whether a host is habitable or not
  223. */
  224. struct GNUNET_TESTBED_HostHabitableCheckHandle *hc_handle;
  225. /**
  226. * The task handle for the delay task
  227. */
  228. GNUNET_SCHEDULER_TaskIdentifier delay_task_id;
  229. /**
  230. * Event mask
  231. */
  232. uint64_t event_mask;
  233. /**
  234. * Global testing status
  235. */
  236. static enum Stage result;
  237. /**
  238. * shortcut to exit during failure
  239. */
  240. #define FAIL_TEST(cond) do { \
  241. if (!(cond)) { \
  242. GNUNET_break(0); \
  243. if (GNUNET_SCHEDULER_NO_TASK != abort_task) \
  244. GNUNET_SCHEDULER_cancel (abort_task); \
  245. abort_task = GNUNET_SCHEDULER_NO_TASK; \
  246. GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \
  247. return; \
  248. } \
  249. } while (0)
  250. /**
  251. * Shutdown nicely
  252. *
  253. * @param cls NULL
  254. * @param tc the task context
  255. */
  256. static void
  257. do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  258. {
  259. if (GNUNET_SCHEDULER_NO_TASK != abort_task)
  260. GNUNET_SCHEDULER_cancel (abort_task);
  261. if (GNUNET_SCHEDULER_NO_TASK != delay_task_id)
  262. {
  263. GNUNET_SCHEDULER_cancel (delay_task_id);
  264. delay_task_id = GNUNET_SCHEDULER_NO_TASK;
  265. }
  266. if (NULL != hc_handle)
  267. GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
  268. if (NULL != mc)
  269. GNUNET_TESTBED_controller_disconnect (mc);
  270. if (NULL != cp)
  271. GNUNET_TESTBED_controller_stop (cp);
  272. if (NULL != slave3)
  273. GNUNET_TESTBED_host_destroy (slave3);
  274. if (NULL != slave2)
  275. GNUNET_TESTBED_host_destroy (slave2);
  276. if (NULL != slave)
  277. GNUNET_TESTBED_host_destroy (slave);
  278. if (NULL != host)
  279. GNUNET_TESTBED_host_destroy (host);
  280. if (NULL != cfg)
  281. GNUNET_CONFIGURATION_destroy (cfg);
  282. if (NULL != cfg3)
  283. GNUNET_CONFIGURATION_destroy (cfg3);
  284. if (NULL != rh)
  285. GNUNET_TESTBED_cancel_registration (rh);
  286. }
  287. /**
  288. * abort task to run on test timed out
  289. *
  290. * @param cls NULL
  291. * @param tc the task context
  292. */
  293. static void
  294. do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  295. {
  296. LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
  297. abort_task = GNUNET_SCHEDULER_NO_TASK;
  298. do_shutdown (cls, tc);
  299. }
  300. /**
  301. * Calls abort now
  302. *
  303. * @param
  304. * @return
  305. */
  306. static void
  307. do_abort_now (void *cls)
  308. {
  309. if (GNUNET_SCHEDULER_NO_TASK != abort_task)
  310. GNUNET_SCHEDULER_cancel (abort_task);
  311. abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
  312. }
  313. /**
  314. * Callback which will be called to after a host registration succeeded or failed
  315. *
  316. * @param cls the host which has been registered
  317. * @param emsg the error message; NULL if host registration is successful
  318. */
  319. static void
  320. registration_cont (void *cls, const char *emsg);
  321. /**
  322. * Task for inserting delay between tests
  323. *
  324. * @param
  325. * @return
  326. */
  327. static void
  328. delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  329. {
  330. delay_task_id = GNUNET_SCHEDULER_NO_TASK;
  331. switch (result)
  332. {
  333. case SLAVE2_PEER_CREATE_SUCCESS:
  334. op = GNUNET_TESTBED_peer_stop (NULL, slave1_peer, NULL, NULL);
  335. FAIL_TEST (NULL != op);
  336. break;
  337. case MASTER_SLAVE2_PEERS_CONNECTED:
  338. slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, cfg, 0);
  339. rh = GNUNET_TESTBED_register_host (mc, slave3, &registration_cont, NULL);
  340. break;
  341. case SLAVE2_SLAVE3_PEERS_CONNECTED:
  342. op = GNUNET_TESTBED_peer_stop (NULL, slave2_peer, NULL, NULL);
  343. FAIL_TEST (NULL != op);
  344. break;
  345. default:
  346. FAIL_TEST (0);
  347. }
  348. }
  349. /**
  350. * Functions of this signature are called when a peer has been successfully
  351. * created
  352. *
  353. * @param cls the closure from GNUNET_TESTBED_peer_create()
  354. * @param peer the handle for the created peer; NULL on any error during
  355. * creation
  356. * @param emsg NULL if peer is not NULL; else MAY contain the error description
  357. */
  358. static void
  359. peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
  360. {
  361. FAIL_TEST (NULL != peer);
  362. FAIL_TEST (NULL == emsg);
  363. switch (result)
  364. {
  365. case MASTER_STARTED:
  366. result = MASTER_PEER_CREATE_SUCCESS;
  367. master_peer = peer;
  368. GNUNET_TESTBED_operation_done (op);
  369. op = GNUNET_TESTBED_peer_start (NULL, master_peer, NULL, NULL);
  370. break;
  371. case SLAVE1_LINK_SUCCESS:
  372. result = SLAVE1_PEER_CREATE_SUCCESS;
  373. slave1_peer = peer;
  374. GNUNET_TESTBED_operation_done (op);
  375. op = GNUNET_TESTBED_peer_start (NULL, slave1_peer, NULL, NULL);
  376. break;
  377. case SLAVE2_LINK_SUCCESS:
  378. result = SLAVE2_PEER_CREATE_SUCCESS;
  379. slave2_peer = peer;
  380. GNUNET_TESTBED_operation_done (op);
  381. delay_task_id =
  382. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
  383. (GNUNET_TIME_UNIT_SECONDS, 1),
  384. &delay_task,
  385. NULL);
  386. break;
  387. case SLAVE3_STARTED:
  388. result = SLAVE3_PEER_CREATE_SUCCESS;
  389. slave3_peer = peer;
  390. GNUNET_TESTBED_operation_done (op);
  391. op = GNUNET_TESTBED_peer_start (NULL, slave3_peer, NULL, NULL);
  392. break;
  393. default:
  394. FAIL_TEST (0);
  395. }
  396. FAIL_TEST (NULL != op);
  397. }
  398. /**
  399. * Checks the event if it is an operation finished event and if indicates a
  400. * successfull completion of operation
  401. *
  402. * @param event the event information to check
  403. */
  404. static void
  405. check_operation_success (const struct GNUNET_TESTBED_EventInformation *event)
  406. {
  407. FAIL_TEST (NULL != event);
  408. FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
  409. FAIL_TEST (event->op == op);
  410. FAIL_TEST (NULL == event->op_cls);
  411. FAIL_TEST (NULL == event->details.operation_finished.emsg);
  412. FAIL_TEST (NULL == event->details.operation_finished.generic);
  413. }
  414. /**
  415. * Signature of the event handler function called by the
  416. * respective event controller.
  417. *
  418. * @param cls closure
  419. * @param event information about the event
  420. */
  421. static void
  422. controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
  423. {
  424. switch (result)
  425. {
  426. case SLAVE2_REGISTERED:
  427. check_operation_success (event);
  428. GNUNET_TESTBED_operation_done (op);
  429. op = NULL;
  430. result = SLAVE1_LINK_SUCCESS;
  431. FAIL_TEST (NULL != slave2);
  432. FAIL_TEST (NULL != slave);
  433. op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL);
  434. FAIL_TEST (NULL != op);
  435. break;
  436. case SLAVE1_PEER_START_SUCCESS:
  437. check_operation_success (event);
  438. GNUNET_TESTBED_operation_done (op);
  439. result = SLAVE2_LINK_SUCCESS;
  440. op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL);
  441. FAIL_TEST (NULL != op);
  442. break;
  443. case MASTER_PEER_CREATE_SUCCESS:
  444. FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
  445. FAIL_TEST (event->details.peer_start.host == host);
  446. FAIL_TEST (event->details.peer_start.peer == master_peer);
  447. GNUNET_TESTBED_operation_done (op);
  448. result = MASTER_PEER_START_SUCCESS;
  449. slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0);
  450. FAIL_TEST (NULL != slave);
  451. rh = GNUNET_TESTBED_register_host (mc, slave, &registration_cont, NULL);
  452. FAIL_TEST (NULL != rh);
  453. break;
  454. case SLAVE1_PEER_CREATE_SUCCESS:
  455. FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
  456. FAIL_TEST (event->details.peer_start.host == slave);
  457. FAIL_TEST (event->details.peer_start.peer == slave1_peer);
  458. GNUNET_TESTBED_operation_done (op);
  459. result = SLAVE1_PEER_START_SUCCESS;
  460. op = GNUNET_TESTBED_controller_link (NULL, mc, slave2, slave, GNUNET_YES);
  461. break;
  462. case SLAVE2_PEER_CREATE_SUCCESS:
  463. FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type);
  464. FAIL_TEST (event->details.peer_stop.peer == slave1_peer);
  465. GNUNET_TESTBED_operation_done (op);
  466. result = SLAVE1_PEER_STOP_SUCCESS;
  467. op = GNUNET_TESTBED_peer_start (NULL, slave2_peer, NULL, NULL);
  468. FAIL_TEST (NULL != op);
  469. break;
  470. case SLAVE3_PEER_CREATE_SUCCESS:
  471. FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
  472. FAIL_TEST (event->details.peer_start.host == slave3);
  473. FAIL_TEST (event->details.peer_start.peer == slave3_peer);
  474. GNUNET_TESTBED_operation_done (op);
  475. result = SLAVE3_PEER_START_SUCCESS;
  476. sleep (1);
  477. LOG_DEBUG ("**************************************\n");
  478. op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer,
  479. slave3_peer);
  480. FAIL_TEST (NULL != op);
  481. break;
  482. case SLAVE3_PEER_START_SUCCESS:
  483. FAIL_TEST (NULL != event);
  484. FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type);
  485. FAIL_TEST (event->details.peer_connect.peer1 == slave2_peer);
  486. FAIL_TEST (event->details.peer_connect.peer2 == slave3_peer);
  487. result = SLAVE2_SLAVE3_PEERS_CONNECTED;
  488. GNUNET_TESTBED_operation_done (op);
  489. op = NULL;
  490. delay_task_id =
  491. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
  492. (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task,
  493. NULL);
  494. break;
  495. case SLAVE1_PEER_STOP_SUCCESS:
  496. FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
  497. FAIL_TEST (event->details.peer_start.host == slave2);
  498. FAIL_TEST (event->details.peer_start.peer == slave2_peer);
  499. GNUNET_TESTBED_operation_done (op);
  500. result = SLAVE2_PEER_START_SUCCESS;
  501. op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer,
  502. slave2_peer);
  503. break;
  504. case SLAVE2_PEER_START_SUCCESS:
  505. FAIL_TEST (NULL != event);
  506. FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type);
  507. FAIL_TEST (event->details.peer_connect.peer1 == master_peer);
  508. FAIL_TEST (event->details.peer_connect.peer2 == slave2_peer);
  509. result = MASTER_SLAVE2_PEERS_CONNECTED;
  510. GNUNET_TESTBED_operation_done (op);
  511. op = NULL;
  512. delay_task_id =
  513. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
  514. (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task,
  515. NULL);
  516. break;
  517. case SLAVE2_SLAVE3_PEERS_CONNECTED:
  518. FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type);
  519. FAIL_TEST (event->details.peer_stop.peer == slave2_peer);
  520. GNUNET_TESTBED_operation_done (op);
  521. result = SLAVE2_PEER_STOP_SUCCESS;
  522. op = GNUNET_TESTBED_peer_destroy (slave1_peer);
  523. FAIL_TEST (NULL != op);
  524. break;
  525. case SLAVE2_PEER_STOP_SUCCESS:
  526. check_operation_success (event);
  527. GNUNET_TESTBED_operation_done (op);
  528. result = SLAVE1_PEER_DESTROY_SUCCESS;
  529. op = GNUNET_TESTBED_peer_destroy (slave2_peer);
  530. FAIL_TEST (NULL != op);
  531. break;
  532. case SLAVE1_PEER_DESTROY_SUCCESS:
  533. check_operation_success (event);
  534. GNUNET_TESTBED_operation_done (op);
  535. op = NULL;
  536. result = SLAVE2_PEER_DESTROY_SUCCESS;
  537. op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3);
  538. FAIL_TEST (NULL != op);
  539. break;
  540. case SLAVE2_PEER_DESTROY_SUCCESS:
  541. FAIL_TEST (NULL != event);
  542. FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
  543. FAIL_TEST (event->op == op);
  544. FAIL_TEST (NULL == event->op_cls);
  545. FAIL_TEST (NULL == event->details.operation_finished.emsg);
  546. cfg3 = GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic);
  547. GNUNET_TESTBED_operation_done (op);
  548. result = SLAVE3_GET_CONFIG_SUCCESS;
  549. op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, slave, GNUNET_NO);
  550. break;
  551. case SLAVE3_REGISTERED:
  552. check_operation_success (event);
  553. GNUNET_TESTBED_operation_done (op);
  554. op = NULL;
  555. result = SLAVE3_STARTED;
  556. op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL);
  557. FAIL_TEST (NULL != op);
  558. break;
  559. case SLAVE3_GET_CONFIG_SUCCESS:
  560. result = SLAVE3_LINK_SUCCESS;
  561. GNUNET_TESTBED_operation_done (op);
  562. op = GNUNET_TESTBED_peer_destroy (master_peer);
  563. break;
  564. case SLAVE3_LINK_SUCCESS:
  565. check_operation_success (event);
  566. result = MASTER_PEER_DESTROY_SUCCESS;
  567. GNUNET_TESTBED_operation_done (op);
  568. op = GNUNET_TESTBED_peer_destroy (slave3_peer);
  569. break;
  570. case MASTER_PEER_DESTROY_SUCCESS:
  571. result = SUCCESS;
  572. GNUNET_TESTBED_operation_done (op);
  573. op = NULL;
  574. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
  575. (GNUNET_TIME_UNIT_SECONDS, 1), &do_shutdown,
  576. NULL);
  577. break;
  578. default:
  579. FAIL_TEST (0);
  580. }
  581. }
  582. /**
  583. * Callback which will be called to after a host registration succeeded or failed
  584. *
  585. * @param cls the host which has been registered
  586. * @param emsg the error message; NULL if host registration is successful
  587. */
  588. static void
  589. registration_cont (void *cls, const char *emsg)
  590. {
  591. rh = NULL;
  592. switch (result)
  593. {
  594. case MASTER_PEER_START_SUCCESS:
  595. FAIL_TEST (NULL == emsg);
  596. FAIL_TEST (NULL != mc);
  597. result = SLAVE1_REGISTERED;
  598. slave2 = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, cfg, 0);
  599. FAIL_TEST (NULL != slave2);
  600. rh = GNUNET_TESTBED_register_host (mc, slave2, &registration_cont, NULL);
  601. FAIL_TEST (NULL != rh);
  602. break;
  603. case SLAVE1_REGISTERED:
  604. FAIL_TEST (NULL == emsg);
  605. FAIL_TEST (NULL != mc);
  606. result = SLAVE2_REGISTERED;
  607. FAIL_TEST (NULL != cfg);
  608. op = GNUNET_TESTBED_controller_link (NULL, mc, slave, NULL, GNUNET_YES);
  609. FAIL_TEST (NULL != op);
  610. break;
  611. case MASTER_SLAVE2_PEERS_CONNECTED:
  612. FAIL_TEST (NULL == emsg);
  613. FAIL_TEST (NULL != mc);
  614. FAIL_TEST (NULL == op);
  615. result = SLAVE3_REGISTERED;
  616. op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, NULL, GNUNET_YES);
  617. FAIL_TEST (NULL != op);
  618. break;
  619. default:
  620. GNUNET_break (0);
  621. do_abort_now (NULL);
  622. }
  623. }
  624. /**
  625. * Callback to signal successfull startup of the controller process
  626. *
  627. * @param cls the closure from GNUNET_TESTBED_controller_start()
  628. * @param cfg the configuration with which the controller has been started;
  629. * NULL if status is not GNUNET_OK
  630. * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
  631. * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
  632. */
  633. static void
  634. status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
  635. int status)
  636. {
  637. switch (result)
  638. {
  639. case INIT:
  640. FAIL_TEST (GNUNET_OK == status);
  641. event_mask = 0;
  642. event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
  643. event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
  644. event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
  645. event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
  646. mc = GNUNET_TESTBED_controller_connect (host, event_mask,
  647. &controller_cb, NULL);
  648. FAIL_TEST (NULL != mc);
  649. result = MASTER_STARTED;
  650. op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL);
  651. FAIL_TEST (NULL != op);
  652. break;
  653. default:
  654. GNUNET_break (0);
  655. cp = NULL;
  656. do_abort_now (NULL);
  657. }
  658. }
  659. /**
  660. * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
  661. * inform whether the given host is habitable or not. The Handle returned by
  662. * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
  663. *
  664. * @param cls NULL
  665. * @param host the host whose status is being reported; will be NULL if the host
  666. * given to GNUNET_TESTBED_is_host_habitable() is NULL
  667. * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
  668. */
  669. static void
  670. host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host,
  671. int status)
  672. {
  673. hc_handle = NULL;
  674. if (GNUNET_NO == status)
  675. {
  676. (void) PRINTF ("%s",
  677. "Unable to run the test as this system is not configured "
  678. "to use password less SSH logins to localhost.\n"
  679. "Skipping test\n");
  680. GNUNET_SCHEDULER_cancel (abort_task);
  681. abort_task = GNUNET_SCHEDULER_NO_TASK;
  682. (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
  683. result = SKIP;
  684. return;
  685. }
  686. cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb,
  687. NULL);
  688. }
  689. /**
  690. * Main run function.
  691. *
  692. * @param cls NULL
  693. * @param args arguments passed to GNUNET_PROGRAM_run
  694. * @param cfgfile the path to configuration file
  695. * @param cfg the configuration file handle
  696. */
  697. static void
  698. run (void *cls, char *const *args, const char *cfgfile,
  699. const struct GNUNET_CONFIGURATION_Handle *config)
  700. {
  701. cfg = GNUNET_CONFIGURATION_dup (config);
  702. host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
  703. FAIL_TEST (NULL != host);
  704. if (NULL ==
  705. (hc_handle =
  706. GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb,
  707. NULL)))
  708. {
  709. GNUNET_TESTBED_host_destroy (host);
  710. GNUNET_CONFIGURATION_destroy (cfg);
  711. cfg = NULL;
  712. host = NULL;
  713. (void) PRINTF ("%s",
  714. "Unable to run the test as this system is not configured "
  715. "to use password less SSH logins to localhost.\n"
  716. "Marking test as successful\n");
  717. result = SKIP;
  718. return;
  719. }
  720. abort_task =
  721. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
  722. (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort,
  723. NULL);
  724. }
  725. /**
  726. * Main function
  727. */
  728. int
  729. main (int argc, char **argv)
  730. {
  731. char *const argv2[] = { "test_testbed_api_controllerlink",
  732. "-c", "test_testbed_api.conf",
  733. NULL
  734. };
  735. struct GNUNET_GETOPT_CommandLineOption options[] = {
  736. GNUNET_GETOPT_OPTION_END
  737. };
  738. int ret;
  739. result = INIT;
  740. ret =
  741. GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
  742. "test_testbed_api_controllerlink", "nohelp", options,
  743. &run, NULL);
  744. if (GNUNET_OK != ret)
  745. return 1;
  746. switch (result)
  747. {
  748. case SUCCESS:
  749. return 0;
  750. case SKIP:
  751. return 77; /* Mark test as skipped */
  752. default:
  753. return 1;
  754. }
  755. }
  756. /* end of test_testbed_api_controllerlink.c */