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/>.
19 * @file ats/test_ats_lib.h
20 * @brief test ATS library with a generic interpreter for running ATS tests
21 * @author Christian Grothoff
23 #ifndef TEST_ATS_LIB_H
24 #define TEST_ATS_LIB_H
26 #include "gnunet_util_lib.h"
27 #include "gnunet_ats_service.h"
28 #include "gnunet_testing_lib.h"
32 * Commands for the interpreter.
37 * End the test (passing).
42 * Call #GNUNET_ATS_address_add().
47 * Call #GNUNET_ATS_address_del().
52 * Wait for ATS to suggest address.
54 CMD_AWAIT_ADDRESS_SUGGESTION,
57 * Wait for ATS to suggest disconnect.
59 CMD_AWAIT_DISCONNECT_SUGGESTION,
62 * Ask ATS to connect to a peer, using
63 * #GNUNET_ATS_connectivity_suggest().
65 CMD_REQUEST_CONNECTION_START,
68 * Tell ATS we no longer need a connection to a peer, using
69 * #GNUNET_ATS_connectivity_suggest_cancel().
71 CMD_REQUEST_CONNECTION_STOP,
74 * Wait for certain address information to be provided.
76 CMD_AWAIT_ADDRESS_INFORMATION,
79 * Update properties of an address, using
80 * #GNUNET_ATS_address_update().
85 * Add session to an address, using
86 * #GNUNET_ATS_address_add_session().
91 * Remove session from an address, using
92 * #GNUNET_ATS_address_del_session().
97 * Change performance preferences for a peer, testing
98 * #GNUNET_ATS_performance_change_preference().
100 CMD_CHANGE_PREFERENCE,
103 * Provide allocation quality feedback, testing
104 * #GNUNET_ATS_performance_give_feedback().
106 CMD_PROVIDE_FEEDBACK,
109 * Obtain list of all addresses, testing
110 * #GNUNET_ATS_performance_list_addresses().
115 * Reserve bandwidth, testing
116 * #GNUNET_ATS_reserve_bandwidth().
118 CMD_RESERVE_BANDWIDTH,
129 * Details for the #CMD_ADD_ADDRESS command.
131 struct CommandAddAddress
134 * Number of the peer (used to generate PID).
139 * Number of the address (used to generate binary address).
141 unsigned int addr_num;
144 * Session to supply, 0 for NULL.
146 unsigned int session;
149 * Flags to set for the address.
151 enum GNUNET_HELLO_AddressInfo addr_flags;
154 * Performance properties to supply.
156 struct GNUNET_ATS_Properties properties;
159 * Expect the operation to fail (duplicate).
164 * Here the result of the add address operation will be stored.
166 struct GNUNET_ATS_AddressRecord *ar;
171 * Details for the #CMD_DEL_ADDRESS command.
173 struct CommandDelAddress
176 * Label of the corresponding #CMD_ADD_ADDRESS that
177 * we are now to remove.
179 const char *add_label;
184 * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
186 struct CommandAwaitAddressSuggestion
189 * For which peer do we expect a suggestion?
194 * If we expect the address suggested to match a particular
195 * addition, specify the label of the add operation here. Otherwise
196 * use NULL for "any" available address.
198 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?
217 * Details for the #CMD_REQUEST_CONNECTION_START command.
219 struct CommandRequestConnectionStart
222 * Identity of the peer we would like to connect to.
227 * Location where we store the handle returned from
228 * #GNUNET_ATS_connectivity_suggest().
230 struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
235 * Details for the #CMD_REQUEST_CONNECTION_STOP command.
237 struct CommandRequestConnectionStop
240 * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
241 * we are now stopping.
243 const char *connect_label;
248 * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
250 struct CommandAwaitAddressInformation
253 * For which address do we expect information?
254 * The address is identified by the respective
255 * label of the corresponding add operation.
257 const char *add_label;
260 * Label of a possible update operation that may
261 * have modified the properties. NULL to use
262 * the properties from the @e add_label.
264 const char *update_label;
270 * Details for the #CMD_UPDATE_ADDRESS command.
272 struct CommandUpdateAddress
275 * Label of the addresses's add operation.
277 const char *add_label;
280 * Performance properties to supply.
282 struct GNUNET_ATS_Properties properties;
288 * Details for the #CMD_ADD_SESSION command.
290 struct CommandAddSession
293 * Label of the addresses's add operation.
295 const char *add_label;
300 unsigned int session;
306 * Details for the #CMD_DEL_SESSION command.
308 struct CommandDelSession
311 * Label of the addresses's add operation.
313 const char *add_session_label;
319 * Details for the #CMD_CHANGE_PREFERENCE command.
321 struct CommandChangePreference
324 * Identity of the peer we have a preference change towards.
328 /* FIXME: preference details! */
334 * Details for the #CMD_PROVIDE_FEEDBACK command.
336 struct CommandProvideFeedback
339 * Identity of the peer we have a feedback for.
344 * Over which timeframe does the feedback apply?
346 struct GNUNET_TIME_Relative scope;
348 /* FIXME: feedback details! */
353 * Details for the #CMD_LIST_ADDRESSES command.
355 struct CommandListAddresses
358 * Identity of the peer we want a list for.
363 * All addresses or just active?
368 * Minimum number of addresses the callback may report.
370 unsigned int min_calls;
373 * Maximum number of addresses the callback may report.
375 unsigned int max_calls;
378 * Minimum number of active addresses the callback may report.
380 unsigned int min_active_calls;
383 * Maximum number of active addresses the callback may report.
385 unsigned int max_active_calls;
388 * Number of calls the command invoked the callback with
389 * an address marked as active. (Set by command).
391 unsigned int active_calls;
394 * Number of calls the command invoked the callback with
395 * any address marked as available to ATS. (Set by command).
400 * Location where we store the return value from
401 * #GNUNET_ATS_performance_list_addresses().
403 struct GNUNET_ATS_AddressListHandle *alh;
409 * Details for the #CMD_RESERVE_BANDWIDTH command.
411 struct CommandReserveBandwidth
414 * For which peer do we reserve bandwidth?
419 * How much should we try to reserve?
424 * Should we expect this to work or fail?
425 * #GNUNET_YES: must work
426 * #GNUNET_NO: may work or fail
427 * #GNUNET_SYSERR: must fail
432 * Location where we store the return value from
433 * #GNUNET_ATS_reserve_bandwidth().
435 struct GNUNET_ATS_ReservationContext *rc;
441 * Details for the #CMD_SLEEP command.
446 * How long should we wait before running the next command?
448 struct GNUNET_TIME_Relative delay;
453 * A command for the test case interpreter.
458 * Command code to run.
460 enum CommandCode code;
463 * Commands can be given a label so we can reference them later.
468 * Additional arguments to commands, if any.
472 struct CommandAddAddress add_address;
474 struct CommandDelAddress del_address;
476 struct CommandAwaitAddressSuggestion await_address_suggestion;
478 struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
480 struct CommandRequestConnectionStart request_connection_start;
482 struct CommandRequestConnectionStop request_connection_stop;
484 struct CommandAwaitAddressInformation await_address_information;
486 struct CommandUpdateAddress update_address;
488 struct CommandAddSession add_session;
490 struct CommandDelSession del_session;
492 struct CommandChangePreference change_preference;
494 struct CommandProvideFeedback provide_feedback;
496 struct CommandListAddresses list_addresses;
498 struct CommandReserveBandwidth reserve_bandwidth;
500 struct CommandSleep sleep;
510 * @param argc length of @a argv
511 * @param argv command line
512 * @param cmds commands to run with the interpreter
513 * @param timeout how long is the test allowed to take?
514 * @return 0 on success
517 TEST_ATS_run (int argc,
519 struct Command *cmds,
520 struct GNUNET_TIME_Relative timeout);