aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_testbed_ng_service.h
blob: a6f30889f52a9ade44df0ea000dc6ec9c5e6fb32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
      This file is part of GNUnet
      Copyright (C) 2021 GNUnet e.V.

      GNUnet is free software: you can redistribute it and/or modify it
      under the terms of the GNU Affero General Public License as published
      by the Free Software Foundation, either version 3 of the License,
      or (at your option) any later version.

      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.

      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.

     SPDX-License-Identifier: AGPL3.0-or-later
 */

/**
 * @author t3sserakt
 *
 * @file
 * API for writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
 *
 * @defgroup testbed  Testbed service
 * Writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
 *
 * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-NG-Subsystem)
 *
 * @{
 */

#ifndef GNUNET_TESTBED_NG_SERVICE_H
#define GNUNET_TESTBED_NG_SERVICE_H

#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"

struct ServiceState
{
  /**
   * Handle to operation
   */
  struct GNUNET_TESTBED_Operation *operation;

  /**
   * Flag indicating if service is ready.
   */
  int service_ready;

  /**
   * Abort task identifier
   */
  struct GNUNET_SCHEDULER_Task *abort_task;

  /**
   * Label of peer command.
   */
  const char *peer_label;

  /**
   * Name of service to start.
   */
  const char *servicename;
};

struct PeerCmdState
{
  /**
   * The label of a controller command.
   */
  const char *controller_label;

  /**
   * Handle to operation
   */
  struct GNUNET_TESTBED_Operation *operation;

  /**
   * Name of the host, use "NULL" for localhost.
   */
  const char *hostname;

  /**
   * Username to use for the login; may be NULL.
   */
  const char *username;

  /**
   * Port number to use for ssh; use 0 to let ssh decide.
   */
  uint16_t port;

  /**
   * The configuration to use as a template while starting a controller
   * on this host.  Operation queue sizes specific to a host are also
   * read from this configuration handle.
   */
  struct GNUNET_CONFIGURATION_Handle *cfg;

  /**
   * The host to run peers and controllers on
   */
  struct GNUNET_TESTBED_Host *host;

  /**
   * Abort task identifier
   */
  struct GNUNET_SCHEDULER_Task *abort_task;

  /**
   * Handle for host registration
   */
  struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;

  /**
   * Flag indicating if peer is ready.
   */
  int peer_ready;

  /**
   * Flag indicating controller is going down.
   */
  int peer_going_down;

  /**
   * Interpreter state.
   */
  struct GNUNET_TESTING_Interpreter *is;

  /**
   * Peer to start
   */
  struct GNUNET_TESTBED_Peer *peer;
};

struct ControllerState
{
  /**
   * The ip address of the controller which will be set as TRUSTED
   * HOST(all connections form this ip are permitted by the testbed) when
   * starting testbed controller at host. This can either be a single ip
   * address or a network address in CIDR notation.
   */
  const char *trusted_ip;

  /**
   * Name of the host, use "NULL" for localhost.
   */
  const char *hostname;

  /**
   * Username to use for the login; may be NULL.
   */
  const char *username;

  /**
   * Port number to use for ssh; use 0 to let ssh decide.
   */
  uint16_t port;

  /**
   * The configuration to use as a template while starting a controller
   * on this host.  Operation queue sizes specific to a host are also
   * read from this configuration handle.
   */
  struct GNUNET_CONFIGURATION_Handle *cfg;

  /**
   * The host to run peers and controllers on
   */
  struct GNUNET_TESTBED_Host *host;

  /**
   * The controller process
   */
  struct GNUNET_TESTBED_ControllerProc *cp;

  /**
   * The controller handle
   */
  struct GNUNET_TESTBED_Controller *controller;

  /**
   * A bit mask with set of events to call the controller for.
   */
  uint64_t event_mask;

  /**
   * Abort task identifier
   */
  struct GNUNET_SCHEDULER_Task *abort_task;

  /**
   * Handle for host registration
   */
  struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;

  /**
   * Flag indicating if host create with controller is ready.
   */
  int host_ready;

  /**
   * Flag indicating controller is going down.
   */
  int controller_going_down;

  /**
   * Interpreter state.
   */
  struct GNUNET_TESTING_Interpreter *is;
};

/**
 * Offer data from trait
 *
 * @param cmd command to extract the controller from.
 * @param pt pointer to controller.
 * @return #GNUNET_OK on success.
 */
int
GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
                                     struct GNUNET_TESTBED_Controller **
                                     controller);

struct GNUNET_TESTING_Command
GNUNET_TESTBED_cmd_controller (const char *label,
                               const char *trusted_ip,
                               const char *hostname,
                               const char *username,
                               uint16_t port,
                               struct GNUNET_CONFIGURATION_Handle *cfg,
                               uint64_t event_mask);

void
GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs);

void
GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps);

void
GNUNET_TESTBED_shutdown_service (struct ServiceState *ss);

#endif