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.
16 * @file ats/test_ats_lib.h
17 * @brief test ATS library with a generic interpreter for running ATS tests
18 * @author Christian Grothoff
20 #ifndef TEST_ATS_LIB_H
21 #define TEST_ATS_LIB_H
23 #include "gnunet_util_lib.h"
24 #include "gnunet_ats_service.h"
25 #include "gnunet_testing_lib.h"
29 * Commands for the interpreter.
34 * End the test (passing).
39 * Call #GNUNET_ATS_address_add().
44 * Call #GNUNET_ATS_address_del().
49 * Wait for ATS to suggest address.
51 CMD_AWAIT_ADDRESS_SUGGESTION,
54 * Wait for ATS to suggest disconnect.
56 CMD_AWAIT_DISCONNECT_SUGGESTION,
59 * Ask ATS to connect to a peer, using
60 * #GNUNET_ATS_connectivity_suggest().
62 CMD_REQUEST_CONNECTION_START,
65 * Tell ATS we no longer need a connection to a peer, using
66 * #GNUNET_ATS_connectivity_suggest_cancel().
68 CMD_REQUEST_CONNECTION_STOP,
71 * Wait for certain address information to be provided.
73 CMD_AWAIT_ADDRESS_INFORMATION,
76 * Update properties of an address, using
77 * #GNUNET_ATS_address_update().
82 * Add session to an address, using
83 * #GNUNET_ATS_address_add_session().
88 * Remove session from an address, using
89 * #GNUNET_ATS_address_del_session().
94 * Change performance preferences for a peer, testing
95 * #GNUNET_ATS_performance_change_preference().
97 CMD_CHANGE_PREFERENCE,
100 * Provide allocation quality feedback, testing
101 * #GNUNET_ATS_performance_give_feedback().
103 CMD_PROVIDE_FEEDBACK,
106 * Obtain list of all addresses, testing
107 * #GNUNET_ATS_performance_list_addresses().
112 * Reserve bandwidth, testing
113 * #GNUNET_ATS_reserve_bandwidth().
115 CMD_RESERVE_BANDWIDTH,
126 * Details for the #CMD_ADD_ADDRESS command.
128 struct CommandAddAddress
131 * Number of the peer (used to generate PID).
136 * Number of the address (used to generate binary address).
138 unsigned int addr_num;
141 * Session to supply, 0 for NULL.
143 unsigned int session;
146 * Flags to set for the address.
148 enum GNUNET_HELLO_AddressInfo addr_flags;
151 * Performance properties to supply.
153 struct GNUNET_ATS_Properties properties;
156 * Expect the operation to fail (duplicate).
161 * Here the result of the add address operation will be stored.
163 struct GNUNET_ATS_AddressRecord *ar;
168 * Details for the #CMD_DEL_ADDRESS command.
170 struct CommandDelAddress
173 * Label of the corresponding #CMD_ADD_ADDRESS that
174 * we are now to remove.
176 const char *add_label;
181 * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
183 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;
201 * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
203 struct CommandAwaitDisconnectSuggestion
206 * For which peer do we expect the disconnect?
214 * Details for the #CMD_REQUEST_CONNECTION_START command.
216 struct CommandRequestConnectionStart
219 * Identity of the peer we would like to connect to.
224 * Location where we store the handle returned from
225 * #GNUNET_ATS_connectivity_suggest().
227 struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
232 * Details for the #CMD_REQUEST_CONNECTION_STOP command.
234 struct CommandRequestConnectionStop
237 * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
238 * we are now stopping.
240 const char *connect_label;
245 * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
247 struct CommandAwaitAddressInformation
250 * For which address do we expect information?
251 * The address is identified by the respective
252 * label of the corresponding add operation.
254 const char *add_label;
257 * Label of a possible update operation that may
258 * have modified the properties. NULL to use
259 * the properties from the @e add_label.
261 const char *update_label;
267 * Details for the #CMD_UPDATE_ADDRESS command.
269 struct CommandUpdateAddress
272 * Label of the addresses's add operation.
274 const char *add_label;
277 * Performance properties to supply.
279 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;
303 * Details for the #CMD_DEL_SESSION command.
305 struct CommandDelSession
308 * Label of the addresses's add operation.
310 const char *add_session_label;
316 * Details for the #CMD_CHANGE_PREFERENCE command.
318 struct CommandChangePreference
321 * Identity of the peer we have a preference change towards.
325 /* FIXME: preference details! */
331 * Details for the #CMD_PROVIDE_FEEDBACK command.
333 struct CommandProvideFeedback
336 * Identity of the peer we have a feedback for.
341 * Over which timeframe does the feedback apply?
343 struct GNUNET_TIME_Relative scope;
345 /* FIXME: feedback details! */
350 * Details for the #CMD_LIST_ADDRESSES command.
352 struct CommandListAddresses
355 * Identity of the peer we want a list for.
360 * All addresses or just active?
365 * Minimum number of addresses the callback may report.
367 unsigned int min_calls;
370 * Maximum number of addresses the callback may report.
372 unsigned int max_calls;
375 * Minimum number of active addresses the callback may report.
377 unsigned int min_active_calls;
380 * Maximum number of active addresses the callback may report.
382 unsigned int max_active_calls;
385 * Number of calls the command invoked the callback with
386 * an address marked as active. (Set by command).
388 unsigned int active_calls;
391 * Number of calls the command invoked the callback with
392 * any address marked as available to ATS. (Set by command).
397 * Location where we store the return value from
398 * #GNUNET_ATS_performance_list_addresses().
400 struct GNUNET_ATS_AddressListHandle *alh;
406 * Details for the #CMD_RESERVE_BANDWIDTH command.
408 struct CommandReserveBandwidth
411 * For which peer do we reserve bandwidth?
416 * How much should we try to reserve?
421 * Should we expect this to work or fail?
422 * #GNUNET_YES: must work
423 * #GNUNET_NO: may work or fail
424 * #GNUNET_SYSERR: must fail
429 * Location where we store the return value from
430 * #GNUNET_ATS_reserve_bandwidth().
432 struct GNUNET_ATS_ReservationContext *rc;
438 * Details for the #CMD_SLEEP command.
443 * How long should we wait before running the next command?
445 struct GNUNET_TIME_Relative delay;
450 * A command for the test case interpreter.
455 * Command code to run.
457 enum CommandCode code;
460 * Commands can be given a label so we can reference them later.
465 * Additional arguments to commands, if any.
469 struct CommandAddAddress add_address;
471 struct CommandDelAddress del_address;
473 struct CommandAwaitAddressSuggestion await_address_suggestion;
475 struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
477 struct CommandRequestConnectionStart request_connection_start;
479 struct CommandRequestConnectionStop request_connection_stop;
481 struct CommandAwaitAddressInformation await_address_information;
483 struct CommandUpdateAddress update_address;
485 struct CommandAddSession add_session;
487 struct CommandDelSession del_session;
489 struct CommandChangePreference change_preference;
491 struct CommandProvideFeedback provide_feedback;
493 struct CommandListAddresses list_addresses;
495 struct CommandReserveBandwidth reserve_bandwidth;
497 struct CommandSleep sleep;
507 * @param argc length of @a argv
508 * @param argv command line
509 * @param cmds commands to run with the interpreter
510 * @param timeout how long is the test allowed to take?
511 * @return 0 on success
514 TEST_ATS_run (int argc,
516 struct Command *cmds,
517 struct GNUNET_TIME_Relative timeout);