gnunet_testbed_ng_service.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2021 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your 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. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author t3sserakt
  18. *
  19. * @file
  20. * API for writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
  21. *
  22. * @defgroup testbed Testbed service
  23. * Writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
  24. *
  25. * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-NG-Subsystem)
  26. *
  27. * @{
  28. */
  29. #ifndef GNUNET_TESTBED_NG_SERVICE_H
  30. #define GNUNET_TESTBED_NG_SERVICE_H
  31. #include "gnunet_util_lib.h"
  32. #include "gnunet_testing_ng_lib.h"
  33. struct TngState;
  34. struct PeerCmdState
  35. {
  36. /**
  37. * The label of a controller command.
  38. */
  39. const char *controller_label;
  40. /**
  41. * Handle to operation
  42. */
  43. struct GNUNET_TESTBED_Operation *operation;
  44. /**
  45. * Name of the host, use "NULL" for localhost.
  46. */
  47. const char *hostname;
  48. /**
  49. * Username to use for the login; may be NULL.
  50. */
  51. const char *username;
  52. /**
  53. * Port number to use for ssh; use 0 to let ssh decide.
  54. */
  55. uint16_t port;
  56. /**
  57. * The configuration to use as a template while starting a controller
  58. * on this host. Operation queue sizes specific to a host are also
  59. * read from this configuration handle.
  60. */
  61. struct GNUNET_CONFIGURATION_Handle *cfg;
  62. /**
  63. * The host to run peers and controllers on
  64. */
  65. struct GNUNET_TESTBED_Host *host;
  66. /**
  67. * Abort task identifier
  68. */
  69. struct GNUNET_SCHEDULER_Task *abort_task;
  70. /**
  71. * Flag indicating if peer is ready.
  72. */
  73. int peer_ready;
  74. /**
  75. * Flag indicating controller is going down.
  76. */
  77. int peer_going_down;
  78. /**
  79. * Interpreter state.
  80. */
  81. struct GNUNET_TESTING_Interpreter *is;
  82. /**
  83. * Peer to start
  84. */
  85. struct GNUNET_TESTBED_Peer *peer;
  86. };
  87. struct ControllerState
  88. {
  89. /**
  90. * The ip address of the controller which will be set as TRUSTED
  91. * HOST(all connections form this ip are permitted by the testbed) when
  92. * starting testbed controller at host. This can either be a single ip
  93. * address or a network address in CIDR notation.
  94. */
  95. const char *trusted_ip;
  96. /**
  97. * Name of the host, use "NULL" for localhost.
  98. */
  99. const char *hostname;
  100. /**
  101. * Username to use for the login; may be NULL.
  102. */
  103. const char *username;
  104. /**
  105. * Port number to use for ssh; use 0 to let ssh decide.
  106. */
  107. uint16_t port;
  108. /**
  109. * The configuration to use as a template while starting a controller
  110. * on this host. Operation queue sizes specific to a host are also
  111. * read from this configuration handle.
  112. */
  113. struct GNUNET_CONFIGURATION_Handle *cfg;
  114. /**
  115. * The host to run peers and controllers on
  116. */
  117. struct GNUNET_TESTBED_Host *host;
  118. /**
  119. * The controller process
  120. */
  121. struct GNUNET_TESTBED_ControllerProc *cp;
  122. /**
  123. * The controller handle
  124. */
  125. struct GNUNET_TESTBED_Controller *controller;
  126. /**
  127. * A bit mask with set of events to call the controller for.
  128. */
  129. uint64_t event_mask;
  130. /**
  131. * Abort task identifier
  132. */
  133. struct GNUNET_SCHEDULER_Task *abort_task;
  134. /**
  135. * Handle for host registration
  136. */
  137. struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
  138. /**
  139. * Flag indicating if host create with controller is ready.
  140. */
  141. int host_ready;
  142. /**
  143. * Flag indicating controller is going down.
  144. */
  145. int controller_going_down;
  146. /**
  147. * Interpreter state.
  148. */
  149. struct GNUNET_TESTING_Interpreter *is;
  150. };
  151. /**
  152. * Offer data from trait
  153. *
  154. * @param cmd command to extract the controller from.
  155. * @param pt pointer to controller.
  156. * @return #GNUNET_OK on success.
  157. */
  158. int
  159. GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
  160. struct GNUNET_TESTBED_Controller **
  161. controller);
  162. struct GNUNET_TESTING_Command
  163. GNUNET_TESTBED_cmd_controller (const char *label,
  164. const char *trusted_ip,
  165. const char *hostname,
  166. const char *username,
  167. uint16_t port,
  168. struct GNUNET_CONFIGURATION_Handle *cfg,
  169. uint64_t event_mask);
  170. void
  171. GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs);
  172. void
  173. GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps);
  174. void
  175. GNUNET_TESTBED_shutdown_service (struct TngState *ss);
  176. #endif