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 ATS Application Handle
32 * Handle to the application-side of ATS.
34 static struct GNUNET_ATS_ApplicationHandle *ah;
37 * @brief ATS Transport Handle
39 * Handle to the transport-side of ATS.
41 static struct GNUNET_ATS_TransportHandle *th;
44 * @brief Another (dummy) peer.
46 * Used as the peer ATS shall allocate bandwidth to.
48 static struct GNUNET_PeerIdentity other_peer;
51 * @brief Handle to the session record
53 static struct GNUNET_ATS_SessionRecord *sr;
56 * @brief Called whenever allocation changed
58 * Implements #GNUNET_ATS_AllocationCallback
62 * @param bandwidth_out
68 allocation_cb (void *cls,
69 struct GNUNET_ATS_Session *session,
70 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
71 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "allocation_cb() called\n");
78 * @brief Called whenever suggestion is made
80 * Implements #GNUNET_ATS_SuggestionCallback
87 suggestion_cb (void *cls,
88 const struct GNUNET_PeerIdentity *pid,
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "suggestion_cb() called\n");
96 * @brief Initialise both 'sides' of ATS
98 * Initialises the application and transportation side of ATS.
101 init_both (const struct GNUNET_CONFIGURATION_Handle *cfg)
103 ah = GNUNET_ATS_application_init (cfg);
104 GNUNET_assert (NULL != ah);
105 th = GNUNET_ATS_transport_init (cfg,
110 GNUNET_assert (NULL != ah);
115 * @brief Disconnect both 'sides' of ATS
120 GNUNET_ATS_application_done (ah);
122 GNUNET_ATS_transport_done (th);
128 * @brief Provide information about the start of an imaginary connection
131 provide_info_start (void)
133 struct GNUNET_ATS_Properties prop =
135 .delay = GNUNET_TIME_UNIT_FOREVER_REL,
136 .goodput_out = 1048576,
137 .goodput_in = 1048576,
138 .utilization_out = 0,
142 .nt = GNUNET_NT_UNSPECIFIED,
143 .cc = GNUNET_TRANSPORT_CC_UNKNOWN,
146 sr = GNUNET_ATS_session_add (th,
155 * @brief Provide information about the end of an imaginary connection
158 provide_info_end (void)
160 GNUNET_ATS_session_del (sr);
165 * @brief Inform ATS about the need of a connection towards a peer
168 get_suggestion (void)
170 struct GNUNET_ATS_ApplicationSuggestHandle *ash;
172 ash = GNUNET_ATS_application_suggest (ah,
174 GNUNET_MQ_PREFERENCE_NONE,
175 GNUNET_BANDWIDTH_VALUE_MAX);
176 GNUNET_ATS_application_suggest_cancel (ash);
181 * Function run once the ATS service has been started.
184 * @param cfg configuration for the testcase
185 * @param peer handle to the peer
189 const struct GNUNET_CONFIGURATION_Handle *cfg,
190 struct GNUNET_TESTING_Peer *peer)
193 provide_info_start ();
201 * @brief Starts the gnunet-testing peer
212 memset (&other_peer, 0, sizeof (struct GNUNET_PeerIdentity));
213 return GNUNET_TESTING_peer_run ("test-ats2-lib",
214 "test_ats2_lib.conf",
220 /* end of test_ats2_lib.c */