summaryrefslogtreecommitdiff
path: root/src/ats/test_ats2_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/test_ats2_lib.c')
-rw-r--r--src/ats/test_ats2_lib.c259
1 files changed, 0 insertions, 259 deletions
diff --git a/src/ats/test_ats2_lib.c b/src/ats/test_ats2_lib.c
deleted file mode 100644
index f2a8eb1ea..000000000
--- a/src/ats/test_ats2_lib.c
+++ /dev/null
@@ -1,259 +0,0 @@
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 Indicates the success of the whole test
31 */
32static int ret;
33
34/**
35 * @brief The time available until the test shuts down
36 */
37static struct GNUNET_TIME_Relative timeout;
38
39/**
40 * @brief ATS Application Handle
41 *
42 * Handle to the application-side of ATS.
43 */
44static struct GNUNET_ATS_ApplicationHandle *ah;
45
46/**
47 * @brief ATS Transport Handle
48 *
49 * Handle to the transport-side of ATS.
50 */
51static struct GNUNET_ATS_TransportHandle *th;
52
53/**
54 * @brief Another (dummy) peer.
55 *
56 * Used as the peer ATS shall allocate bandwidth to.
57 */
58static struct GNUNET_PeerIdentity other_peer;
59
60/**
61 * @brief Handle to the session record
62 */
63static struct GNUNET_ATS_SessionRecord *sr;
64
65
66/**
67 * @brief Called whenever allocation changed
68 *
69 * Implements #GNUNET_ATS_AllocationCallback
70 *
71 * @param cls
72 * @param session
73 * @param bandwidth_out
74 * @param bandwidth_in
75 *
76 * @return
77 */
78static void
79allocation_cb (void *cls,
80 struct GNUNET_ATS_Session *session,
81 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
82 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
83{
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "allocation_cb() called\n");
86}
87
88
89/**
90 * @brief Called whenever suggestion is made
91 *
92 * Implements #GNUNET_ATS_SuggestionCallback
93 *
94 * @param cls
95 * @param pid
96 * @param address
97 */
98static void
99suggestion_cb (void *cls,
100 const struct GNUNET_PeerIdentity *pid,
101 const char *address)
102{
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
104 "suggestion_cb() called\n");
105 ret = 0;
106}
107
108
109/**
110 * @brief Initialise both 'sides' of ATS
111 *
112 * Initialises the application and transportation side of ATS.
113 */
114static void
115init_both (const struct GNUNET_CONFIGURATION_Handle *cfg)
116{
117 ah = GNUNET_ATS_application_init (cfg);
118 GNUNET_assert (NULL != ah);
119 th = GNUNET_ATS_transport_init (cfg,
120 &allocation_cb,
121 NULL,
122 &suggestion_cb,
123 NULL);
124 GNUNET_assert (NULL != ah);
125}
126
127
128/**
129 * @brief Disconnect both 'sides' of ATS
130 */
131static void
132finish_both (void)
133{
134 GNUNET_ATS_application_done (ah);
135 ah = NULL;
136 GNUNET_ATS_transport_done (th);
137 th = NULL;
138}
139
140
141/**
142 * @brief Provide information about the start of an imaginary connection
143 */
144static void
145provide_info_start (void)
146{
147 struct GNUNET_ATS_Properties prop = {
148 .delay = GNUNET_TIME_UNIT_FOREVER_REL,
149 .goodput_out = 1048576,
150 .goodput_in = 1048576,
151 .utilization_out = 0,
152 .utilization_in = 0,
153 .distance = 0,
154 .mtu = UINT32_MAX,
155 .nt = GNUNET_NT_UNSPECIFIED,
156 .cc = GNUNET_TRANSPORT_CC_UNKNOWN,
157 };
158
159 sr = GNUNET_ATS_session_add (th,
160 &other_peer,
161 "test-address",
162 NULL,
163 &prop);
164 GNUNET_assert (NULL != sr);
165}
166
167
168/**
169 * @brief Provide information about the end of an imaginary connection
170 */
171static void
172provide_info_end (void)
173{
174 GNUNET_ATS_session_del (sr);
175}
176
177
178/**
179 * @brief Inform ATS about the need of a connection towards a peer
180 */
181static void
182get_suggestion (void)
183{
184 struct GNUNET_ATS_ApplicationSuggestHandle *ash;
185
186 ash = GNUNET_ATS_application_suggest (ah,
187 &other_peer,
188 GNUNET_MQ_PREFERENCE_NONE,
189 GNUNET_BANDWIDTH_VALUE_MAX);
190 GNUNET_assert (NULL != ash);
191}
192
193
194static void
195on_shutdown (void *cls)
196{
197 provide_info_end ();
198 finish_both ();
199 GNUNET_SCHEDULER_shutdown ();
200}
201
202
203/**
204 * Function run once the ATS service has been started.
205 *
206 * @param cls NULL
207 * @param cfg configuration for the testcase
208 * @param peer handle to the peer
209 */
210static void
211run (void *cls,
212 const struct GNUNET_CONFIGURATION_Handle *cfg,
213 struct GNUNET_TESTING_Peer *peer)
214{
215 init_both (cfg);
216 provide_info_start ();
217 get_suggestion ();
218 (void) GNUNET_SCHEDULER_add_delayed (timeout,
219 &on_shutdown,
220 NULL);
221}
222
223
224/**
225 * @brief Starts the gnunet-testing peer
226 *
227 * @param argc
228 * @param argv[]
229 *
230 * @return
231 */
232int
233main (int argc,
234 char *argv[])
235{
236 ret = 1;
237 memset (&other_peer, 0, sizeof(struct GNUNET_PeerIdentity));
238 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
239 2);
240 if (0 != GNUNET_TESTING_peer_run ("test-ats2-lib",
241 "test_ats2_lib.conf",
242 &run, NULL))
243 {
244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
245 "Running the testing peer failed.\n");
246 return 1;
247 }
248 if (0 != ret)
249 {
250 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
251 "Global status indicates unsuccessful testrun - probably allocation_cb was not called.\n");
252 ret = 77; // SKIP test, test not yet right!
253 }
254 return ret;
255}
256
257
258
259/* end of test_ats2_lib.c */