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.
39 * End the test (passing).
44 * Call #GNUNET_ATS_address_add().
49 * Call #GNUNET_ATS_address_del().
54 * Wait for ATS to suggest address.
56 CMD_AWAIT_ADDRESS_SUGGESTION,
59 * Wait for ATS to suggest disconnect.
61 CMD_AWAIT_DISCONNECT_SUGGESTION,
64 * Ask ATS to connect to a peer, using
65 * #GNUNET_ATS_connectivity_suggest().
67 CMD_REQUEST_CONNECTION_START,
70 * Tell ATS we no longer need a connection to a peer, using
71 * #GNUNET_ATS_connectivity_suggest_cancel().
73 CMD_REQUEST_CONNECTION_STOP,
76 * Wait for certain address information to be provided.
78 CMD_AWAIT_ADDRESS_INFORMATION,
81 * Update properties of an address, using
82 * #GNUNET_ATS_address_update().
87 * Add session to an address, using
88 * #GNUNET_ATS_address_add_session().
93 * Remove session from an address, using
94 * #GNUNET_ATS_address_del_session().
99 * Change performance preferences for a peer, testing
100 * #GNUNET_ATS_performance_change_preference().
102 CMD_CHANGE_PREFERENCE,
105 * Provide allocation quality feedback, testing
106 * #GNUNET_ATS_performance_give_feedback().
108 CMD_PROVIDE_FEEDBACK,
111 * Obtain list of all addresses, testing
112 * #GNUNET_ATS_performance_list_addresses().
117 * Reserve bandwidth, testing
118 * #GNUNET_ATS_reserve_bandwidth().
120 CMD_RESERVE_BANDWIDTH,
130 * Details for the #CMD_ADD_ADDRESS command.
132 struct CommandAddAddress
135 * Number of the peer (used to generate PID).
140 * Number of the address (used to generate binary address).
142 unsigned int addr_num;
145 * Session to supply, 0 for NULL.
147 unsigned int session;
150 * Flags to set for the address.
152 enum GNUNET_HELLO_AddressInfo addr_flags;
155 * Performance properties to supply.
157 struct GNUNET_ATS_Properties properties;
160 * Expect the operation to fail (duplicate).
165 * Here the result of the add address operation will be stored.
167 struct GNUNET_ATS_AddressRecord *ar;
172 * Details for the #CMD_DEL_ADDRESS command.
174 struct CommandDelAddress
177 * Label of the corresponding #CMD_ADD_ADDRESS that
178 * we are now to remove.
180 const char *add_label;
185 * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
187 struct CommandAwaitAddressSuggestion
190 * For which peer do we expect a suggestion?
195 * If we expect the address suggested to match a particular
196 * addition, specify the label of the add operation here. Otherwise
197 * use NULL for "any" available address.
199 const char *add_label;
204 * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
206 struct CommandAwaitDisconnectSuggestion
209 * For which peer do we expect the disconnect?
216 * Details for the #CMD_REQUEST_CONNECTION_START command.
218 struct CommandRequestConnectionStart
221 * Identity of the peer we would like to connect to.
226 * Location where we store the handle returned from
227 * #GNUNET_ATS_connectivity_suggest().
229 struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
234 * Details for the #CMD_REQUEST_CONNECTION_STOP command.
236 struct CommandRequestConnectionStop
239 * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
240 * we are now stopping.
242 const char *connect_label;
247 * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
249 struct CommandAwaitAddressInformation
252 * For which address do we expect information?
253 * The address is identified by the respective
254 * label of the corresponding add operation.
256 const char *add_label;
259 * Label of a possible update operation that may
260 * have modified the properties. NULL to use
261 * the properties from the @e add_label.
263 const char *update_label;
268 * Details for the #CMD_UPDATE_ADDRESS command.
270 struct CommandUpdateAddress
273 * Label of the addresses's add operation.
275 const char *add_label;
278 * Performance properties to supply.
280 struct GNUNET_ATS_Properties properties;
285 * Details for the #CMD_ADD_SESSION command.
287 struct CommandAddSession
290 * Label of the addresses's add operation.
292 const char *add_label;
297 unsigned int session;
302 * Details for the #CMD_DEL_SESSION command.
304 struct CommandDelSession
307 * Label of the addresses's add operation.
309 const char *add_session_label;
314 * Details for the #CMD_CHANGE_PREFERENCE command.
316 struct CommandChangePreference
319 * Identity of the peer we have a preference change towards.
323 /* FIXME: preference details! */
328 * Details for the #CMD_PROVIDE_FEEDBACK command.
330 struct CommandProvideFeedback
333 * Identity of the peer we have a feedback for.
338 * Over which timeframe does the feedback apply?
340 struct GNUNET_TIME_Relative scope;
342 /* FIXME: feedback details! */
347 * Details for the #CMD_LIST_ADDRESSES command.
349 struct CommandListAddresses
352 * Identity of the peer we want a list for.
357 * All addresses or just active?
362 * Minimum number of addresses the callback may report.
364 unsigned int min_calls;
367 * Maximum number of addresses the callback may report.
369 unsigned int max_calls;
372 * Minimum number of active addresses the callback may report.
374 unsigned int min_active_calls;
377 * Maximum number of active addresses the callback may report.
379 unsigned int max_active_calls;
382 * Number of calls the command invoked the callback with
383 * an address marked as active. (Set by command).
385 unsigned int active_calls;
388 * Number of calls the command invoked the callback with
389 * any address marked as available to ATS. (Set by command).
394 * Location where we store the return value from
395 * #GNUNET_ATS_performance_list_addresses().
397 struct GNUNET_ATS_AddressListHandle *alh;
402 * Details for the #CMD_RESERVE_BANDWIDTH command.
404 struct CommandReserveBandwidth
407 * For which peer do we reserve bandwidth?
412 * How much should we try to reserve?
417 * Should we expect this to work or fail?
418 * #GNUNET_YES: must work
419 * #GNUNET_NO: may work or fail
420 * #GNUNET_SYSERR: must fail
425 * Location where we store the return value from
426 * #GNUNET_ATS_reserve_bandwidth().
428 struct GNUNET_ATS_ReservationContext *rc;
433 * Details for the #CMD_SLEEP command.
438 * How long should we wait before running the next command?
440 struct GNUNET_TIME_Relative delay;
445 * A command for the test case interpreter.
450 * Command code to run.
452 enum CommandCode code;
455 * Commands can be given a label so we can reference them later.
460 * Additional arguments to commands, if any.
464 struct CommandAddAddress add_address;
466 struct CommandDelAddress del_address;
468 struct CommandAwaitAddressSuggestion await_address_suggestion;
470 struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
472 struct CommandRequestConnectionStart request_connection_start;
474 struct CommandRequestConnectionStop request_connection_stop;
476 struct CommandAwaitAddressInformation await_address_information;
478 struct CommandUpdateAddress update_address;
480 struct CommandAddSession add_session;
482 struct CommandDelSession del_session;
484 struct CommandChangePreference change_preference;
486 struct CommandProvideFeedback provide_feedback;
488 struct CommandListAddresses list_addresses;
490 struct CommandReserveBandwidth reserve_bandwidth;
492 struct CommandSleep sleep;
500 * @param argc length of @a argv
501 * @param argv command line
502 * @param cmds commands to run with the interpreter
503 * @param timeout how long is the test allowed to take?
504 * @return 0 on success
507 TEST_ATS_run (int argc,
509 struct Command *cmds,
510 struct GNUNET_TIME_Relative timeout);