2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file ats/test_ats_lib.h
22 * @brief test ATS library with a generic interpreter for running ATS tests
23 * @author Christian Grothoff
25 #ifndef TEST_ATS_LIB_H
26 #define TEST_ATS_LIB_H
28 #include "gnunet_util_lib.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet_testing_lib.h"
34 * Commands for the interpreter.
38 * End the test (passing).
43 * Call #GNUNET_ATS_address_add().
48 * Call #GNUNET_ATS_address_del().
53 * Wait for ATS to suggest address.
55 CMD_AWAIT_ADDRESS_SUGGESTION,
58 * Wait for ATS to suggest disconnect.
60 CMD_AWAIT_DISCONNECT_SUGGESTION,
63 * Ask ATS to connect to a peer, using
64 * #GNUNET_ATS_connectivity_suggest().
66 CMD_REQUEST_CONNECTION_START,
69 * Tell ATS we no longer need a connection to a peer, using
70 * #GNUNET_ATS_connectivity_suggest_cancel().
72 CMD_REQUEST_CONNECTION_STOP,
75 * Wait for certain address information to be provided.
77 CMD_AWAIT_ADDRESS_INFORMATION,
80 * Update properties of an address, using
81 * #GNUNET_ATS_address_update().
86 * Add session to an address, using
87 * #GNUNET_ATS_address_add_session().
92 * Remove session from an address, using
93 * #GNUNET_ATS_address_del_session().
98 * Change performance preferences for a peer, testing
99 * #GNUNET_ATS_performance_change_preference().
101 CMD_CHANGE_PREFERENCE,
104 * Provide allocation quality feedback, testing
105 * #GNUNET_ATS_performance_give_feedback().
107 CMD_PROVIDE_FEEDBACK,
110 * Obtain list of all addresses, testing
111 * #GNUNET_ATS_performance_list_addresses().
116 * Reserve bandwidth, testing
117 * #GNUNET_ATS_reserve_bandwidth().
119 CMD_RESERVE_BANDWIDTH,
129 * Details for the #CMD_ADD_ADDRESS command.
131 struct CommandAddAddress {
133 * Number of the peer (used to generate PID).
138 * Number of the address (used to generate binary address).
140 unsigned int addr_num;
143 * Session to supply, 0 for NULL.
145 unsigned int session;
148 * Flags to set for the address.
150 enum GNUNET_HELLO_AddressInfo addr_flags;
153 * Performance properties to supply.
155 struct GNUNET_ATS_Properties properties;
158 * Expect the operation to fail (duplicate).
163 * Here the result of the add address operation will be stored.
165 struct GNUNET_ATS_AddressRecord *ar;
170 * Details for the #CMD_DEL_ADDRESS command.
172 struct CommandDelAddress {
174 * Label of the corresponding #CMD_ADD_ADDRESS that
175 * we are now to remove.
177 const char *add_label;
182 * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
184 struct CommandAwaitAddressSuggestion {
186 * For which peer do we expect a suggestion?
191 * If we expect the address suggested to match a particular
192 * addition, specify the label of the add operation here. Otherwise
193 * use NULL for "any" available address.
195 const char *add_label;
200 * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
202 struct CommandAwaitDisconnectSuggestion {
204 * For which peer do we expect the disconnect?
211 * Details for the #CMD_REQUEST_CONNECTION_START command.
213 struct CommandRequestConnectionStart {
215 * Identity of the peer we would like to connect to.
220 * Location where we store the handle returned from
221 * #GNUNET_ATS_connectivity_suggest().
223 struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
228 * Details for the #CMD_REQUEST_CONNECTION_STOP command.
230 struct CommandRequestConnectionStop {
232 * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
233 * we are now stopping.
235 const char *connect_label;
240 * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
242 struct CommandAwaitAddressInformation {
244 * For which address do we expect information?
245 * The address is identified by the respective
246 * label of the corresponding add operation.
248 const char *add_label;
251 * Label of a possible update operation that may
252 * have modified the properties. NULL to use
253 * the properties from the @e add_label.
255 const char *update_label;
260 * Details for the #CMD_UPDATE_ADDRESS command.
262 struct CommandUpdateAddress {
264 * Label of the addresses's add operation.
266 const char *add_label;
269 * Performance properties to supply.
271 struct GNUNET_ATS_Properties properties;
276 * Details for the #CMD_ADD_SESSION command.
278 struct CommandAddSession {
280 * Label of the addresses's add operation.
282 const char *add_label;
287 unsigned int session;
292 * Details for the #CMD_DEL_SESSION command.
294 struct CommandDelSession {
296 * Label of the addresses's add operation.
298 const char *add_session_label;
303 * Details for the #CMD_CHANGE_PREFERENCE command.
305 struct CommandChangePreference {
307 * Identity of the peer we have a preference change towards.
311 /* FIXME: preference details! */
316 * Details for the #CMD_PROVIDE_FEEDBACK command.
318 struct CommandProvideFeedback {
320 * Identity of the peer we have a feedback for.
325 * Over which timeframe does the feedback apply?
327 struct GNUNET_TIME_Relative scope;
329 /* FIXME: feedback details! */
334 * Details for the #CMD_LIST_ADDRESSES command.
336 struct CommandListAddresses {
338 * Identity of the peer we want a list for.
343 * All addresses or just active?
348 * Minimum number of addresses the callback may report.
350 unsigned int min_calls;
353 * Maximum number of addresses the callback may report.
355 unsigned int max_calls;
358 * Minimum number of active addresses the callback may report.
360 unsigned int min_active_calls;
363 * Maximum number of active addresses the callback may report.
365 unsigned int max_active_calls;
368 * Number of calls the command invoked the callback with
369 * an address marked as active. (Set by command).
371 unsigned int active_calls;
374 * Number of calls the command invoked the callback with
375 * any address marked as available to ATS. (Set by command).
380 * Location where we store the return value from
381 * #GNUNET_ATS_performance_list_addresses().
383 struct GNUNET_ATS_AddressListHandle *alh;
388 * Details for the #CMD_RESERVE_BANDWIDTH command.
390 struct CommandReserveBandwidth {
392 * For which peer do we reserve bandwidth?
397 * How much should we try to reserve?
402 * Should we expect this to work or fail?
403 * #GNUNET_YES: must work
404 * #GNUNET_NO: may work or fail
405 * #GNUNET_SYSERR: must fail
410 * Location where we store the return value from
411 * #GNUNET_ATS_reserve_bandwidth().
413 struct GNUNET_ATS_ReservationContext *rc;
418 * Details for the #CMD_SLEEP command.
420 struct CommandSleep {
422 * How long should we wait before running the next command?
424 struct GNUNET_TIME_Relative delay;
429 * A command for the test case interpreter.
433 * Command code to run.
435 enum CommandCode code;
438 * Commands can be given a label so we can reference them later.
443 * Additional arguments to commands, if any.
446 struct CommandAddAddress add_address;
448 struct CommandDelAddress del_address;
450 struct CommandAwaitAddressSuggestion await_address_suggestion;
452 struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
454 struct CommandRequestConnectionStart request_connection_start;
456 struct CommandRequestConnectionStop request_connection_stop;
458 struct CommandAwaitAddressInformation await_address_information;
460 struct CommandUpdateAddress update_address;
462 struct CommandAddSession add_session;
464 struct CommandDelSession del_session;
466 struct CommandChangePreference change_preference;
468 struct CommandProvideFeedback provide_feedback;
470 struct CommandListAddresses list_addresses;
472 struct CommandReserveBandwidth reserve_bandwidth;
474 struct CommandSleep sleep;
482 * @param argc length of @a argv
483 * @param argv command line
484 * @param cmds commands to run with the interpreter
485 * @param timeout how long is the test allowed to take?
486 * @return 0 on success
489 TEST_ATS_run(int argc,
491 struct Command *cmds,
492 struct GNUNET_TIME_Relative timeout);