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_ats2_lib.c
20 * @brief test ATS library with a generic interpreter for running ATS tests
21 * @author Julius Bünger
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"
30 * @brief Indicates the success of the whole test
36 * @brief The time available until the test shuts down
38 static struct GNUNET_TIME_Relative timeout;
42 * @brief ATS Application Handle
44 * Handle to the application-side of ATS.
46 static struct GNUNET_ATS_ApplicationHandle *ah;
49 * @brief ATS Transport Handle
51 * Handle to the transport-side of ATS.
53 static struct GNUNET_ATS_TransportHandle *th;
56 * @brief Another (dummy) peer.
58 * Used as the peer ATS shall allocate bandwidth to.
60 static struct GNUNET_PeerIdentity other_peer;
63 * @brief Handle to the session record
65 static struct GNUNET_ATS_SessionRecord *sr;
68 * @brief Called whenever allocation changed
70 * Implements #GNUNET_ATS_AllocationCallback
74 * @param bandwidth_out
80 allocation_cb (void *cls,
81 struct GNUNET_ATS_Session *session,
82 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
83 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "allocation_cb() called\n");
90 * @brief Called whenever suggestion is made
92 * Implements #GNUNET_ATS_SuggestionCallback
99 suggestion_cb (void *cls,
100 const struct GNUNET_PeerIdentity *pid,
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "suggestion_cb() called\n");
109 * @brief Initialise both 'sides' of ATS
111 * Initialises the application and transportation side of ATS.
114 init_both (const struct GNUNET_CONFIGURATION_Handle *cfg)
116 ah = GNUNET_ATS_application_init (cfg);
117 GNUNET_assert (NULL != ah);
118 th = GNUNET_ATS_transport_init (cfg,
123 GNUNET_assert (NULL != ah);
128 * @brief Disconnect both 'sides' of ATS
133 GNUNET_ATS_application_done (ah);
135 GNUNET_ATS_transport_done (th);
141 * @brief Provide information about the start of an imaginary connection
144 provide_info_start (void)
146 struct GNUNET_ATS_Properties prop =
148 .delay = GNUNET_TIME_UNIT_FOREVER_REL,
149 .goodput_out = 1048576,
150 .goodput_in = 1048576,
151 .utilization_out = 0,
155 .nt = GNUNET_NT_UNSPECIFIED,
156 .cc = GNUNET_TRANSPORT_CC_UNKNOWN,
159 sr = GNUNET_ATS_session_add (th,
164 GNUNET_assert (NULL != sr);
169 * @brief Provide information about the end of an imaginary connection
172 provide_info_end (void)
174 GNUNET_ATS_session_del (sr);
179 * @brief Inform ATS about the need of a connection towards a peer
182 get_suggestion (void)
184 struct GNUNET_ATS_ApplicationSuggestHandle *ash;
186 ash = GNUNET_ATS_application_suggest (ah,
188 GNUNET_MQ_PREFERENCE_NONE,
189 GNUNET_BANDWIDTH_VALUE_MAX);
190 GNUNET_assert (NULL != ash);
195 on_shutdown (void *cls)
199 GNUNET_SCHEDULER_shutdown ();
204 * Function run once the ATS service has been started.
207 * @param cfg configuration for the testcase
208 * @param peer handle to the peer
212 const struct GNUNET_CONFIGURATION_Handle *cfg,
213 struct GNUNET_TESTING_Peer *peer)
216 provide_info_start ();
218 (void) GNUNET_SCHEDULER_add_delayed (timeout,
225 * @brief Starts the gnunet-testing peer
237 memset (&other_peer, 0, sizeof (struct GNUNET_PeerIdentity));
238 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
240 if (0 != GNUNET_TESTING_peer_run ("test-ats2-lib",
241 "test_ats2_lib.conf",
244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running the testing peer failed.\n");
252 /* end of test_ats2_lib.c */