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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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,
131 * Details for the #CMD_ADD_ADDRESS command.
133 struct CommandAddAddress
136 * Number of the peer (used to generate PID).
141 * Number of the address (used to generate binary address).
143 unsigned int addr_num;
146 * Session to supply, 0 for NULL.
148 unsigned int session;
151 * Flags to set for the address.
153 enum GNUNET_HELLO_AddressInfo addr_flags;
156 * Performance properties to supply.
158 struct GNUNET_ATS_Properties properties;
161 * Expect the operation to fail (duplicate).
166 * Here the result of the add address operation will be stored.
168 struct GNUNET_ATS_AddressRecord *ar;
173 * Details for the #CMD_DEL_ADDRESS command.
175 struct CommandDelAddress
178 * Label of the corresponding #CMD_ADD_ADDRESS that
179 * we are now to remove.
181 const char *add_label;
186 * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
188 struct CommandAwaitAddressSuggestion
191 * For which peer do we expect a suggestion?
196 * If we expect the address suggested to match a particular
197 * addition, specify the label of the add operation here. Otherwise
198 * use NULL for "any" available address.
200 const char *add_label;
206 * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
208 struct CommandAwaitDisconnectSuggestion
211 * For which peer do we expect the disconnect?
219 * Details for the #CMD_REQUEST_CONNECTION_START command.
221 struct CommandRequestConnectionStart
224 * Identity of the peer we would like to connect to.
229 * Location where we store the handle returned from
230 * #GNUNET_ATS_connectivity_suggest().
232 struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
237 * Details for the #CMD_REQUEST_CONNECTION_STOP command.
239 struct CommandRequestConnectionStop
242 * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
243 * we are now stopping.
245 const char *connect_label;
250 * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
252 struct CommandAwaitAddressInformation
255 * For which address do we expect information?
256 * The address is identified by the respective
257 * label of the corresponding add operation.
259 const char *add_label;
262 * Label of a possible update operation that may
263 * have modified the properties. NULL to use
264 * the properties from the @e add_label.
266 const char *update_label;
272 * Details for the #CMD_UPDATE_ADDRESS command.
274 struct CommandUpdateAddress
277 * Label of the addresses's add operation.
279 const char *add_label;
282 * Performance properties to supply.
284 struct GNUNET_ATS_Properties properties;
290 * Details for the #CMD_ADD_SESSION command.
292 struct CommandAddSession
295 * Label of the addresses's add operation.
297 const char *add_label;
302 unsigned int session;
308 * Details for the #CMD_DEL_SESSION command.
310 struct CommandDelSession
313 * Label of the addresses's add operation.
315 const char *add_session_label;
321 * Details for the #CMD_CHANGE_PREFERENCE command.
323 struct CommandChangePreference
326 * Identity of the peer we have a preference change towards.
330 /* FIXME: preference details! */
336 * Details for the #CMD_PROVIDE_FEEDBACK command.
338 struct CommandProvideFeedback
341 * Identity of the peer we have a feedback for.
346 * Over which timeframe does the feedback apply?
348 struct GNUNET_TIME_Relative scope;
350 /* FIXME: feedback details! */
355 * Details for the #CMD_LIST_ADDRESSES command.
357 struct CommandListAddresses
360 * Identity of the peer we want a list for.
365 * All addresses or just active?
370 * Minimum number of addresses the callback may report.
372 unsigned int min_calls;
375 * Maximum number of addresses the callback may report.
377 unsigned int max_calls;
380 * Minimum number of active addresses the callback may report.
382 unsigned int min_active_calls;
385 * Maximum number of active addresses the callback may report.
387 unsigned int max_active_calls;
390 * Number of calls the command invoked the callback with
391 * an address marked as active. (Set by command).
393 unsigned int active_calls;
396 * Number of calls the command invoked the callback with
397 * any address marked as available to ATS. (Set by command).
402 * Location where we store the return value from
403 * #GNUNET_ATS_performance_list_addresses().
405 struct GNUNET_ATS_AddressListHandle *alh;
411 * Details for the #CMD_RESERVE_BANDWIDTH command.
413 struct CommandReserveBandwidth
416 * For which peer do we reserve bandwidth?
421 * How much should we try to reserve?
426 * Should we expect this to work or fail?
427 * #GNUNET_YES: must work
428 * #GNUNET_NO: may work or fail
429 * #GNUNET_SYSERR: must fail
434 * Location where we store the return value from
435 * #GNUNET_ATS_reserve_bandwidth().
437 struct GNUNET_ATS_ReservationContext *rc;
443 * Details for the #CMD_SLEEP command.
448 * How long should we wait before running the next command?
450 struct GNUNET_TIME_Relative delay;
455 * A command for the test case interpreter.
460 * Command code to run.
462 enum CommandCode code;
465 * Commands can be given a label so we can reference them later.
470 * Additional arguments to commands, if any.
474 struct CommandAddAddress add_address;
476 struct CommandDelAddress del_address;
478 struct CommandAwaitAddressSuggestion await_address_suggestion;
480 struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
482 struct CommandRequestConnectionStart request_connection_start;
484 struct CommandRequestConnectionStop request_connection_stop;
486 struct CommandAwaitAddressInformation await_address_information;
488 struct CommandUpdateAddress update_address;
490 struct CommandAddSession add_session;
492 struct CommandDelSession del_session;
494 struct CommandChangePreference change_preference;
496 struct CommandProvideFeedback provide_feedback;
498 struct CommandListAddresses list_addresses;
500 struct CommandReserveBandwidth reserve_bandwidth;
502 struct CommandSleep sleep;
512 * @param argc length of @a argv
513 * @param argv command line
514 * @param cmds commands to run with the interpreter
515 * @param timeout how long is the test allowed to take?
516 * @return 0 on success
519 TEST_ATS_run (int argc,
521 struct Command *cmds,
522 struct GNUNET_TIME_Relative timeout);