aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2019-01-23 18:41:33 +0100
committerJulius Bünger <buenger@mytum.de>2019-01-23 18:42:31 +0100
commit546f01e2008e79b6774fd69116f1387bc6ee0409 (patch)
tree5382b384ae46b72725b7fe4cc623a12812ce02cd /src/ats
parentff10602f5ab7df06dc850206159e76bd7a7891ea (diff)
downloadgnunet-546f01e2008e79b6774fd69116f1387bc6ee0409.tar.gz
gnunet-546f01e2008e79b6774fd69116f1387bc6ee0409.zip
ATS: Add first stub of test for new ATS API
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/Makefile.am13
-rw-r--r--src/ats/test_ats2_lib.c220
-rw-r--r--src/ats/test_ats2_lib.h523
3 files changed, 755 insertions, 1 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 147d371e6..f113d96e7 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -141,7 +141,8 @@ gnunet_service_ats_new_LDADD = \
141if HAVE_TESTING 141if HAVE_TESTING
142TESTING_TESTS = \ 142TESTING_TESTS = \
143 test_ats_api_proportional \ 143 test_ats_api_proportional \
144 test_ats_reservation_api_proportional 144 test_ats_reservation_api_proportional \
145 test_ats2_lib
145if HAVE_EXPERIMENTAL 146if HAVE_EXPERIMENTAL
146TESTING_TESTS += \ 147TESTING_TESTS += \
147 test_ats_api_ril 148 test_ats_api_ril
@@ -196,6 +197,16 @@ test_ats_api_mlp_LDADD = \
196 $(top_builddir)/src/testing/libgnunettesting.la \ 197 $(top_builddir)/src/testing/libgnunettesting.la \
197 libgnunetats.la 198 libgnunetats.la
198 199
200test_ats2_lib_SOURCES = \
201 test_ats2_lib.c test_ats2_lib.h
202test_ats2_lib_LDADD = \
203 $(top_builddir)/src/util/libgnunetutil.la \
204 $(top_builddir)/src/hello/libgnunethello.la \
205 $(top_builddir)/src/testing/libgnunettesting.la \
206 libgnunetatsapplication.la \
207 libgnunetatstransport.la
208
209
199EXTRA_DIST = \ 210EXTRA_DIST = \
200 ats.h ats2.h \ 211 ats.h ats2.h \
201 plugin_ats2_common.c \ 212 plugin_ats2_common.c \
diff --git a/src/ats/test_ats2_lib.c b/src/ats/test_ats2_lib.c
new file mode 100644
index 000000000..a35b5bce6
--- /dev/null
+++ b/src/ats/test_ats2_lib.c
@@ -0,0 +1,220 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 GNUnet e.V.
4
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.
9
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.
14
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/>.
17*/
18/**
19 * @file ats/test_ats2_lib.c
20 * @brief test ATS library with a generic interpreter for running ATS tests
21 * @author Julius Bünger
22 */
23#include "platform.h"
24#include "gnunet_util_lib.h"
25#include "gnunet_ats_application_service.h"
26#include "gnunet_ats_transport_service.h"
27#include "gnunet_testing_lib.h"
28
29/**
30 * @brief ATS Application Handle
31 *
32 * Handle to the application-side of ATS.
33 */
34static struct GNUNET_ATS_ApplicationHandle *ah;
35
36/**
37 * @brief ATS Transport Handle
38 *
39 * Handle to the transport-side of ATS.
40 */
41static struct GNUNET_ATS_TransportHandle *th;
42
43/**
44 * @brief Another (dummy) peer.
45 *
46 * Used as the peer ATS shall allocate bandwidth to.
47 */
48static struct GNUNET_PeerIdentity other_peer;
49
50/**
51 * @brief Handle to the session record
52 */
53static struct GNUNET_ATS_SessionRecord *sr;
54
55/**
56 * @brief Called whenever allocation changed
57 *
58 * Implements #GNUNET_ATS_AllocationCallback
59 *
60 * @param cls
61 * @param session
62 * @param bandwidth_out
63 * @param bandwidth_in
64 *
65 * @return
66 */
67static void
68allocation_cb (void *cls,
69 struct GNUNET_ATS_Session *session,
70 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
71 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
72{
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "allocation_cb() called\n");
74}
75
76
77/**
78 * @brief Called whenever suggestion is made
79 *
80 * Implements #GNUNET_ATS_SuggestionCallback
81 *
82 * @param cls
83 * @param pid
84 * @param address
85 */
86static void
87suggestion_cb (void *cls,
88 const struct GNUNET_PeerIdentity *pid,
89 const char *address)
90{
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "suggestion_cb() called\n");
92}
93
94
95/**
96 * @brief Initialise both 'sides' of ATS
97 *
98 * Initialises the application and transportation side of ATS.
99 */
100static void
101init_both (const struct GNUNET_CONFIGURATION_Handle *cfg)
102{
103 ah = GNUNET_ATS_application_init (cfg);
104 GNUNET_assert (NULL != ah);
105 th = GNUNET_ATS_transport_init (cfg,
106 allocation_cb,
107 NULL,
108 suggestion_cb,
109 NULL);
110 GNUNET_assert (NULL != ah);
111}
112
113
114/**
115 * @brief Disconnect both 'sides' of ATS
116 */
117static void
118finish_both (void)
119{
120 GNUNET_ATS_application_done (ah);
121 ah = NULL;
122 GNUNET_ATS_transport_done (th);
123 th = NULL;
124}
125
126
127/**
128 * @brief Provide information about the start of an imaginary connection
129 */
130static void
131provide_info_start (void)
132{
133 struct GNUNET_ATS_Properties prop =
134 {
135 .delay = GNUNET_TIME_UNIT_FOREVER_REL,
136 .goodput_out = 1048576,
137 .goodput_in = 1048576,
138 .utilization_out = 0,
139 .utilization_in = 0,
140 .distance = 0,
141 .mtu = UINT32_MAX,
142 .nt = GNUNET_NT_UNSPECIFIED,
143 .cc = GNUNET_TRANSPORT_CC_UNKNOWN,
144 };
145
146 sr = GNUNET_ATS_session_add (th,
147 &other_peer,
148 "test-address",
149 NULL,
150 &prop);
151}
152
153
154/**
155 * @brief Provide information about the end of an imaginary connection
156 */
157static void
158provide_info_end (void)
159{
160 GNUNET_ATS_session_del (sr);
161}
162
163
164/**
165 * @brief Inform ATS about the need of a connection towards a peer
166 */
167static void
168get_suggestion (void)
169{
170 struct GNUNET_ATS_ApplicationSuggestHandle *ash;
171
172 ash = GNUNET_ATS_application_suggest (ah,
173 &other_peer,
174 GNUNET_MQ_PREFERENCE_NONE,
175 GNUNET_BANDWIDTH_VALUE_MAX);
176 GNUNET_ATS_application_suggest_cancel (ash);
177}
178
179
180/**
181 * Function run once the ATS service has been started.
182 *
183 * @param cls NULL
184 * @param cfg configuration for the testcase
185 * @param peer handle to the peer
186 */
187static void
188run (void *cls,
189 const struct GNUNET_CONFIGURATION_Handle *cfg,
190 struct GNUNET_TESTING_Peer *peer)
191{
192 init_both (cfg);
193 provide_info_start ();
194 get_suggestion ();
195 provide_info_end ();
196 finish_both ();
197}
198
199
200/**
201 * @brief Starts the gnunet-testing peer
202 *
203 * @param argc
204 * @param argv[]
205 *
206 * @return
207 */
208int
209main (int argc,
210 char *argv[])
211{
212 memset (&other_peer, 0, sizeof (struct GNUNET_PeerIdentity));
213 return GNUNET_TESTING_peer_run ("test-ats2-lib",
214 "test_ats2_lib.conf",
215 &run, NULL);
216}
217
218
219
220/* end of test_ats2_lib.c */
diff --git a/src/ats/test_ats2_lib.h b/src/ats/test_ats2_lib.h
new file mode 100644
index 000000000..5c1518792
--- /dev/null
+++ b/src/ats/test_ats2_lib.h
@@ -0,0 +1,523 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 GNUnet e.V.
4
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.
9
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.
14
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/>.
17*/
18/**
19 * @file ats/test_ats_lib.h
20 * @brief test ATS library with a generic interpreter for running ATS tests
21 * @author Christian Grothoff
22 */
23#ifndef TEST_ATS_LIB_H
24#define TEST_ATS_LIB_H
25
26#include "gnunet_util_lib.h"
27#include "gnunet_ats_application_service.h"
28#include "gnunet_ats_transport_service.h"
29#include "gnunet_testing_lib.h"
30
31
32///**
33// * Commands for the interpreter.
34// */
35//enum CommandCode
36//{
37// /**
38// * End the test (passing).
39// */
40// CMD_END_PASS = 0,
41//
42// /**
43// * Call #GNUNET_ATS_address_add().
44// */
45// CMD_ADD_ADDRESS,
46//
47// /**
48// * Call #GNUNET_ATS_address_del().
49// */
50// CMD_DEL_ADDRESS,
51//
52// /**
53// * Wait for ATS to suggest address.
54// */
55// CMD_AWAIT_ADDRESS_SUGGESTION,
56//
57// /**
58// * Wait for ATS to suggest disconnect.
59// */
60// CMD_AWAIT_DISCONNECT_SUGGESTION,
61//
62// /**
63// * Ask ATS to connect to a peer, using
64// * #GNUNET_ATS_connectivity_suggest().
65// */
66// CMD_REQUEST_CONNECTION_START,
67//
68// /**
69// * Tell ATS we no longer need a connection to a peer, using
70// * #GNUNET_ATS_connectivity_suggest_cancel().
71// */
72// CMD_REQUEST_CONNECTION_STOP,
73//
74// /**
75// * Wait for certain address information to be provided.
76// */
77// CMD_AWAIT_ADDRESS_INFORMATION,
78//
79// /**
80// * Update properties of an address, using
81// * #GNUNET_ATS_address_update().
82// */
83// CMD_UPDATE_ADDRESS,
84//
85// /**
86// * Add session to an address, using
87// * #GNUNET_ATS_address_add_session().
88// */
89// CMD_ADD_SESSION,
90//
91// /**
92// * Remove session from an address, using
93// * #GNUNET_ATS_address_del_session().
94// */
95// CMD_DEL_SESSION,
96//
97// /**
98// * Change performance preferences for a peer, testing
99// * #GNUNET_ATS_performance_change_preference().
100// */
101// CMD_CHANGE_PREFERENCE,
102//
103// /**
104// * Provide allocation quality feedback, testing
105// * #GNUNET_ATS_performance_give_feedback().
106// */
107// CMD_PROVIDE_FEEDBACK,
108//
109// /**
110// * Obtain list of all addresses, testing
111// * #GNUNET_ATS_performance_list_addresses().
112// */
113// CMD_LIST_ADDRESSES,
114//
115// /**
116// * Reserve bandwidth, testing
117// * #GNUNET_ATS_reserve_bandwidth().
118// */
119// CMD_RESERVE_BANDWIDTH,
120//
121// /**
122// * Wait for a bit.
123// */
124// CMD_SLEEP
125//
126//};
127//
128//
129///**
130// * Details for the #CMD_ADD_ADDRESS command.
131// */
132//struct CommandAddAddress
133//{
134// /**
135// * Number of the peer (used to generate PID).
136// */
137// unsigned int pid;
138//
139// /**
140// * Number of the address (used to generate binary address).
141// */
142// unsigned int addr_num;
143//
144// /**
145// * Session to supply, 0 for NULL.
146// */
147// unsigned int session;
148//
149// /**
150// * Flags to set for the address.
151// */
152// enum GNUNET_HELLO_AddressInfo addr_flags;
153//
154// /**
155// * Performance properties to supply.
156// */
157// struct GNUNET_ATS_Properties properties;
158//
159// /**
160// * Expect the operation to fail (duplicate).
161// */
162// int expect_fail;
163//
164// /**
165// * Here the result of the add address operation will be stored.
166// */
167// struct GNUNET_ATS_AddressRecord *ar;
168//};
169//
170//
171///**
172// * Details for the #CMD_DEL_ADDRESS command.
173// */
174//struct CommandDelAddress
175//{
176// /**
177// * Label of the corresponding #CMD_ADD_ADDRESS that
178// * we are now to remove.
179// */
180// const char *add_label;
181//};
182//
183//
184///**
185// * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
186// */
187//struct CommandAwaitAddressSuggestion
188//{
189// /**
190// * For which peer do we expect a suggestion?
191// */
192// unsigned int pid;
193//
194// /**
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.
198// */
199// const char *add_label;
200//
201//};
202//
203//
204///**
205// * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
206// */
207//struct CommandAwaitDisconnectSuggestion
208//{
209// /**
210// * For which peer do we expect the disconnect?
211// */
212// unsigned int pid;
213//
214//};
215//
216//
217///**
218// * Details for the #CMD_REQUEST_CONNECTION_START command.
219// */
220//struct CommandRequestConnectionStart
221//{
222// /**
223// * Identity of the peer we would like to connect to.
224// */
225// unsigned int pid;
226//
227// /**
228// * Location where we store the handle returned from
229// * #GNUNET_ATS_connectivity_suggest().
230// */
231// struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
232//};
233//
234//
235///**
236// * Details for the #CMD_REQUEST_CONNECTION_STOP command.
237// */
238//struct CommandRequestConnectionStop
239//{
240// /**
241// * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
242// * we are now stopping.
243// */
244// const char *connect_label;
245//};
246//
247//
248///**
249// * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
250// */
251//struct CommandAwaitAddressInformation
252//{
253// /**
254// * For which address do we expect information?
255// * The address is identified by the respective
256// * label of the corresponding add operation.
257// */
258// const char *add_label;
259//
260// /**
261// * Label of a possible update operation that may
262// * have modified the properties. NULL to use
263// * the properties from the @e add_label.
264// */
265// const char *update_label;
266//
267//};
268//
269//
270///**
271// * Details for the #CMD_UPDATE_ADDRESS command.
272// */
273//struct CommandUpdateAddress
274//{
275// /**
276// * Label of the addresses's add operation.
277// */
278// const char *add_label;
279//
280// /**
281// * Performance properties to supply.
282// */
283// struct GNUNET_ATS_Properties properties;
284//
285//};
286//
287//
288///**
289// * Details for the #CMD_ADD_SESSION command.
290// */
291//struct CommandAddSession
292//{
293// /**
294// * Label of the addresses's add operation.
295// */
296// const char *add_label;
297//
298// /**
299// * Session to supply.
300// */
301// unsigned int session;
302//
303//};
304//
305//
306///**
307// * Details for the #CMD_DEL_SESSION command.
308// */
309//struct CommandDelSession
310//{
311// /**
312// * Label of the addresses's add operation.
313// */
314// const char *add_session_label;
315//
316//};
317//
318//
319///**
320// * Details for the #CMD_CHANGE_PREFERENCE command.
321// */
322//struct CommandChangePreference
323//{
324// /**
325// * Identity of the peer we have a preference change towards.
326// */
327// unsigned int pid;
328//
329// /* FIXME: preference details! */
330//
331//};
332//
333//
334///**
335// * Details for the #CMD_PROVIDE_FEEDBACK command.
336// */
337//struct CommandProvideFeedback
338//{
339// /**
340// * Identity of the peer we have a feedback for.
341// */
342// unsigned int pid;
343//
344// /**
345// * Over which timeframe does the feedback apply?
346// */
347// struct GNUNET_TIME_Relative scope;
348//
349// /* FIXME: feedback details! */
350//};
351//
352//
353///**
354// * Details for the #CMD_LIST_ADDRESSES command.
355// */
356//struct CommandListAddresses
357//{
358// /**
359// * Identity of the peer we want a list for.
360// */
361// unsigned int pid;
362//
363// /**
364// * All addresses or just active?
365// */
366// int all;
367//
368// /**
369// * Minimum number of addresses the callback may report.
370// */
371// unsigned int min_calls;
372//
373// /**
374// * Maximum number of addresses the callback may report.
375// */
376// unsigned int max_calls;
377//
378// /**
379// * Minimum number of active addresses the callback may report.
380// */
381// unsigned int min_active_calls;
382//
383// /**
384// * Maximum number of active addresses the callback may report.
385// */
386// unsigned int max_active_calls;
387//
388// /**
389// * Number of calls the command invoked the callback with
390// * an address marked as active. (Set by command).
391// */
392// unsigned int active_calls;
393//
394// /**
395// * Number of calls the command invoked the callback with
396// * any address marked as available to ATS. (Set by command).
397// */
398// unsigned int calls;
399//
400// /**
401// * Location where we store the return value from
402// * #GNUNET_ATS_performance_list_addresses().
403// */
404// struct GNUNET_ATS_AddressListHandle *alh;
405//
406//};
407//
408//
409///**
410// * Details for the #CMD_RESERVE_BANDWIDTH command.
411// */
412//struct CommandReserveBandwidth
413//{
414// /**
415// * For which peer do we reserve bandwidth?
416// */
417// unsigned int pid;
418//
419// /**
420// * How much should we try to reserve?
421// */
422// int32_t amount;
423//
424// /**
425// * Should we expect this to work or fail?
426// * #GNUNET_YES: must work
427// * #GNUNET_NO: may work or fail
428// * #GNUNET_SYSERR: must fail
429// */
430// int expected_result;
431//
432// /**
433// * Location where we store the return value from
434// * #GNUNET_ATS_reserve_bandwidth().
435// */
436// struct GNUNET_ATS_ReservationContext *rc;
437//
438//};
439//
440//
441///**
442// * Details for the #CMD_SLEEP command.
443// */
444//struct CommandSleep
445//{
446// /**
447// * How long should we wait before running the next command?
448// */
449// struct GNUNET_TIME_Relative delay;
450//};
451//
452//
453///**
454// * A command for the test case interpreter.
455// */
456//struct Command
457//{
458// /**
459// * Command code to run.
460// */
461// enum CommandCode code;
462//
463// /**
464// * Commands can be given a label so we can reference them later.
465// */
466// const char *label;
467//
468// /**
469// * Additional arguments to commands, if any.
470// */
471// union {
472//
473// struct CommandAddAddress add_address;
474//
475// struct CommandDelAddress del_address;
476//
477// struct CommandAwaitAddressSuggestion await_address_suggestion;
478//
479// struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion;
480//
481// struct CommandRequestConnectionStart request_connection_start;
482//
483// struct CommandRequestConnectionStop request_connection_stop;
484//
485// struct CommandAwaitAddressInformation await_address_information;
486//
487// struct CommandUpdateAddress update_address;
488//
489// struct CommandAddSession add_session;
490//
491// struct CommandDelSession del_session;
492//
493// struct CommandChangePreference change_preference;
494//
495// struct CommandProvideFeedback provide_feedback;
496//
497// struct CommandListAddresses list_addresses;
498//
499// struct CommandReserveBandwidth reserve_bandwidth;
500//
501// struct CommandSleep sleep;
502//
503// } details;
504//
505//};
506
507
508/**
509 * Run ATS test.
510 *
511 * @param argc length of @a argv
512 * @param argv command line
513 * @param cmds commands to run with the interpreter
514 * @param timeout how long is the test allowed to take?
515 * @return 0 on success
516 */
517int
518TEST_ATS_run (int argc,
519 char *argv[],
520 struct Command *cmds,
521 struct GNUNET_TIME_Relative timeout);
522
523#endif