1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
/*
This file is part of GNUnet.
Copyright (C) 2010-2015 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file ats/test_ats_lib.h
* @brief test ATS library with a generic interpreter for running ATS tests
* @author Christian Grothoff
*/
#ifndef TEST_ATS_LIB_H
#define TEST_ATS_LIB_H
#include "gnunet_util_lib.h"
#include "gnunet_ats_service.h"
#include "gnunet_testing_lib.h"
/**
* Commands for the interpreter.
*/
enum CommandCode
{
/**
* End the test (passing).
*/
CMD_END_PASS = 0,
/**
* Call #GNUNET_ATS_address_add().
*/
CMD_ADD_ADDRESS,
/**
* Call #GNUNET_ATS_address_del().
*/
CMD_DEL_ADDRESS,
/**
* Wait for ATS to suggest address.
*/
CMD_AWAIT_ADDRESS_SUGGESTION,
/**
* Wait for ATS to suggest disconnect.
*/
CMD_AWAIT_DISCONNECT_SUGGESTION,
/**
* Ask ATS to connect to a peer, using
* #GNUNET_ATS_connectivity_suggest().
*/
CMD_REQUEST_CONNECTION_START,
/**
* Tell ATS we no longer need a connection to a peer, using
* #GNUNET_ATS_connectivity_suggest_cancel().
*/
CMD_REQUEST_CONNECTION_STOP,
/**
* Wait for certain address information to be provided.
*/
CMD_AWAIT_ADDRESS_INFORMATION,
/**
* Update properties of an address, using
* #GNUNET_ATS_address_update().
*/
CMD_UPDATE_ADDRESS,
/**
* Add session to an address, using
* #GNUNET_ATS_address_add_session().
*/
CMD_ADD_SESSION,
/**
* Remove session from an address, using
* #GNUNET_ATS_address_del_session().
*/
CMD_DEL_SESSION,
/**
* Change performance preferences for a peer, testing
* #GNUNET_ATS_performance_change_preference().
*/
CMD_CHANGE_PREFERENCE,
/**
* Provide allocation quality feedback, testing
* #GNUNET_ATS_performance_give_feedback().
*/
CMD_PROVIDE_FEEDBACK,
/**
* Obtain list of all addresses, testing
* #GNUNET_ATS_performance_list_addresses().
*/
CMD_LIST_ADDRESSES,
/**
* Reserve bandwidth, testing
* #GNUNET_ATS_reserve_bandwidth().
*/
CMD_RESERVE_BANDWIDTH,
/**
* Wait for a bit.
*/
CMD_SLEEP
};
/**
* Details for the #CMD_ADD_ADDRESS command.
*/
struct CommandAddAddress
{
/**
* Number of the peer (used to generate PID).
*/
unsigned int pid;
/**
* Number of the address (used to generate binary address).
*/
unsigned int addr_num;
/**
* Session to supply, 0 for NULL.
*/
unsigned int session;
/**
* Flags to set for the address.
*/
enum GNUNET_HELLO_AddressInfo addr_flags;
/**
* Performance properties to supply.
*/
struct GNUNET_ATS_Properties properties;
/**
* Expect the operation to fail (duplicate).
*/
int expect_fail;
/**
* Here the result of the add address operation will be stored.
*/
struct GNUNET_ATS_AddressRecord *ar;
};
/**
* Details for the #CMD_DEL_ADDRESS command.
*/
struct CommandDelAddress
{
/**
* Label of the corresponding #CMD_ADD_ADDRESS that
* we are now to remove.
*/
const char *add_label;
};
/**
* Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
*/
struct CommandAwaitAddressSuggestion
{
/**
* For which peer do we expect a suggestion?
*/
unsigned int pid;
/**
* If we expect the address suggested to match a particular
* addition, specify the label of the add operation here. Otherwise
* use NULL for "any" available address.
*/
const char *add_label;
};
/**
* Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
*/
struct CommandAwaitDisconnectSuggestion
{
/**
* For which peer do we expect the disconnect?
*/
unsigned int pid;
};
/**
* Details for the #CMD_REQUEST_CONNECTION_START command.
*/
struct CommandRequestConnectionStart
{
/**
* Identity of the peer we would like to connect to.
*/
unsigned int pid;
/**
* Location where we store the handle returned from
* #GNUNET_ATS_connectivity_suggest().
*/
struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
};
/**
* Details for the #CMD_REQUEST_CONNECTION_STOP command.
*/
struct CommandRequestConnectionStop
{
/**
* Label of the corresponding #CMD_REQUEST_CONNECTION_START that
* we are now stopping.
*/
const char *connect_label;
};
/**
* Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
*/
struct CommandAwaitAddressInformation
{
/**
* For which address do we expect information?
* The address is identified by the respective
* label of the corresponding add operation.
*/
const char *add_label;
/**
* Label of a possible update operation that may
* have modified the properties. NULL to use
* the properties from the @e add_label.
*/
const char *update_label;
};
/**
* Details for the #CMD_UPDATE_ADDRESS command.
*/
struct CommandUpdateAddress
{
/**
* Label of the addresses's add operation.
*/
const char *add_label;
/**
* Performance properties to supply.
*/
struct GNUNET_ATS_Properties properties;
};
/**
* Details for the #CMD_ADD_SESSION command.
*/
struct CommandAddSession
{
/**
* Label of the addresses's add operation.
*/
const char *add_label;
/**
* Session to supply.
*/
unsigned int session;
};
/**
* Details for the #CMD_DEL_SESSION command.
*/
struct CommandDelSession
{
/**
* Label of the addresses's add operation.
*/
const char *add_session_label;
};
/**
* Details for the #CMD_CHANGE_PREFERENCE command.
*/
struct CommandChangePreference
{
/**
* Identity of the peer we have a preference change towards.
*/
unsigned int pid;
/* FIXME: preference details! */
};
/**
* Details for the #CMD_PROVIDE_FEEDBACK command.
*/
struct CommandProvideFeedback
{
/**
* Identity of the peer we have a feedback for.
*/
unsigned int pid;
/**
* Over which timeframe does the feedback apply?
*/
struct GNUNET_TIME_Relative scope;
/* FIXME: feedback details! */
};
/**
* Details for the #CMD_LIST_ADDRESSES command.
*/
struct CommandListAddresses
{
/**
* Identity of the peer we want a list for.
*/
unsigned int pid;
/**
* All addresses or just active?
*/
int all;
/**
* Minimum number of addresses the callback may report.
*/
unsigned int min_calls;
/**
* Maximum number of addresses the callback may report.
*/
unsigned int max_calls;
/**
* Minimum number of active addresses the callback may report.
*/
unsigned int min_active_calls;
/**
* Maximum number of active addresses the callback may report.
*/
unsigned int max_active_calls;
/**
* Number of calls the command invoked the callback with
* an address marked as active. (Set by command).
*/
unsigned int active_calls;
/**
* Number of calls the command invoked the callback with
* any address marked as available to ATS. (Set by command).
*/
unsigned int calls;
/**
* Location where we store the return value from
* #GNUNET_ATS_performance_list_addresses().
*/
struct GNUNET_ATS_AddressListHandle *alh;
};
/**
* Details for the #CMD_RESERVE_BANDWIDTH command.
*/
struct CommandReserveBandwidth
{
/**
* For which peer do we reserve bandwidth?
*/
unsigned int pid;
/**
* How much should we try to reserve?
*/
int32_t amount;
/**
* Should we expect this to work or fail?
* #GNUNET_YES: must work
* #GNUNET_NO: may work or fail
* #GNUNET_SYSERR: must fail
*/
int expected_result;
/**
* Location where we store the return value from
* #GNUNET_ATS_reserve_bandwidth().
*/
struct GNUNET_ATS_ReservationContext *rc;
};
/**
* Details for the #CMD_SLEEP command.
*/
struct CommandSleep
{
/**
* How long should we wait before running the next command?
*/
struct GNUNET_TIME_Relative delay;
};
/**
* A command for the test case interpreter.
*/
struct Command
{
/**
* Command code to run.
*/
enum CommandCode code;
/**
* Commands can be given a label so we can reference them later.
*/
const char *label;
/**
* Additional arguments to commands, if any.
*/
union {
struct CommandAddAddress add_address;
struct CommandDelAddress del_address;
struct CommandAwaitAddressSuggestion await_address_suggestion;
struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
struct CommandRequestConnectionStart request_connection_start;
struct CommandRequestConnectionStop request_connection_stop;
struct CommandAwaitAddressInformation await_address_information;
struct CommandUpdateAddress update_address;
struct CommandAddSession add_session;
struct CommandDelSession del_session;
struct CommandChangePreference change_preference;
struct CommandProvideFeedback provide_feedback;
struct CommandListAddresses list_addresses;
struct CommandReserveBandwidth reserve_bandwidth;
struct CommandSleep sleep;
} details;
};
/**
* Run ATS test.
*
* @param argc length of @a argv
* @param argv command line
* @param cmds commands to run with the interpreter
* @param timeout how long is the test allowed to take?
* @return 0 on success
*/
int
TEST_ATS_run (int argc,
char *argv[],
struct Command *cmds,
struct GNUNET_TIME_Relative timeout);
#endif
|